home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / macros / texinfo / elisp / texinfmt.el < prev    next >
Lisp/Scheme  |  1992-09-16  |  102KB  |  2,752 lines

  1. ;;;; texinfmt.el
  2.  
  3. ;;; Emacs lisp functions to convert Texinfo files to Info files.
  4.  
  5. (defvar texinfmt-version "2.26 of 15 September 1992")
  6.  
  7. ;;; Robert J. Chassell          
  8. ;;; Please send bug reports to:  bob@gnu.ai.mit.edu
  9.  
  10. ;;; Copyright (C) 1985, 1986, 1988,
  11. ;;;               1990, 1991, 1992  Free Software Foundation, Inc.
  12.  
  13.  
  14. ;;; This file is part of GNU Emacs.
  15.  
  16. ;; GNU Emacs is free software; you can redistribute it and/or modify
  17. ;; it under the terms of the GNU General Public License as published by
  18. ;; the Free Software Foundation; either version 2, or (at your option)
  19. ;; any later version.
  20.  
  21. ;; GNU Emacs is distributed in the hope that it will be useful,
  22. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  24. ;; GNU General Public License for more details.
  25.  
  26. ;; You should have received a copy of the GNU General Public License
  27. ;; along with GNU Emacs; see the file COPYING.  If not, write to
  28. ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  29.  
  30.  
  31. ;;; Variable definitions
  32.  
  33. (require 'texinfo)              ; So `texinfo-footnote-style' is defined.
  34.  
  35. (defvar texinfo-format-syntax-table nil)
  36.  
  37. (defvar texinfo-vindex)
  38. (defvar texinfo-findex)
  39. (defvar texinfo-cindex)
  40. (defvar texinfo-pindex)
  41. (defvar texinfo-tindex)
  42. (defvar texinfo-kindex)
  43. (defvar texinfo-last-node)
  44. (defvar texinfo-node-names)
  45. (defvar texinfo-enclosure-list)
  46.  
  47.  
  48. ;;; Syntax table
  49.  
  50. (if texinfo-format-syntax-table
  51.     nil
  52.   (setq texinfo-format-syntax-table (make-syntax-table))
  53.   (modify-syntax-entry ?\" " " texinfo-format-syntax-table)
  54.   (modify-syntax-entry ?\\ " " texinfo-format-syntax-table)
  55.   (modify-syntax-entry ?@ "\\" texinfo-format-syntax-table)
  56.   (modify-syntax-entry ?\^q "\\" texinfo-format-syntax-table)
  57.   (modify-syntax-entry ?\[ "." texinfo-format-syntax-table)
  58.   (modify-syntax-entry ?\] "." texinfo-format-syntax-table)
  59.   (modify-syntax-entry ?\( "." texinfo-format-syntax-table)
  60.   (modify-syntax-entry ?\) "." texinfo-format-syntax-table)
  61.   (modify-syntax-entry ?{ "(}" texinfo-format-syntax-table)
  62.   (modify-syntax-entry ?} "){" texinfo-format-syntax-table)
  63.   (modify-syntax-entry ?\' "." texinfo-format-syntax-table))
  64.  
  65.  
  66. ;;; Top level buffer and region formatting functions
  67.  
  68. (defun texinfo-format-buffer (&optional notagify)
  69.   "Process the current buffer as texinfo code, into an Info file.
  70. The Info file output is generated in a buffer visiting the Info file
  71. names specified in the @setfilename command.
  72.  
  73. Non-nil argument (prefix, if interactive) means don't make tag table
  74. and don't split the file if large.  You can use Info-tagify and
  75. Info-split to do these manually."
  76.   (interactive "P")
  77.   (let ((lastmessage "Formatting Info file..."))
  78.     (message lastmessage)
  79.     (texinfo-format-buffer-1)
  80.     (if notagify
  81.         nil
  82.       (if (> (buffer-size) 30000)
  83.           (progn
  84.             (message (setq lastmessage "Making tags table for Info file..."))
  85.             (Info-tagify)))
  86.       (if (> (buffer-size) 100000)
  87.           (progn
  88.             (message (setq lastmessage "Splitting Info file..."))
  89.             (Info-split))))
  90.     (message (concat lastmessage
  91.                      (if (interactive-p) "done.  Now save it." "done.")))))
  92.  
  93. (defvar texinfo-region-buffer-name "*Info Region*"
  94.   "*Name of the temporary buffer used by \\[texinfo-format-region].")
  95.  
  96. (defun texinfo-format-region (region-beginning region-ending)
  97.   "Convert the current region of the Texinfo file to Info format.
  98. This lets you see what that part of the file will look like in Info.
  99. The command is bound to \\[texinfo-format-region].  The text that is
  100. converted to Info is stored in a temporary buffer."
  101.   (interactive "r")
  102.   (message "Converting region to Info format...")
  103.   (let (texinfo-command-start
  104.         texinfo-command-end
  105.         texinfo-command-name
  106.         texinfo-vindex
  107.         texinfo-findex
  108.         texinfo-cindex
  109.         texinfo-pindex
  110.         texinfo-tindex
  111.         texinfo-kindex
  112.         texinfo-stack
  113.         texinfo-format-filename
  114.         texinfo-example-start
  115.         texinfo-last-node-pos
  116.         texinfo-last-node
  117.         texinfo-node-names
  118.     (texinfo-footnote-number 0)
  119.         last-input-buffer
  120.         (fill-column-for-info fill-column)
  121.         (input-buffer (current-buffer))
  122.         (input-directory default-directory)
  123.         filename-or-header
  124.         filename-or-header-beginning
  125.         filename-or-header-end)
  126.     
  127. ;;; Find a buffer to use.
  128.     
  129.     (switch-to-buffer (get-buffer-create texinfo-region-buffer-name))
  130.     (erase-buffer)
  131.  
  132.     ;; Insert the region into the buffer.
  133.     
  134.     ;; First, find file name or tell of its absence.
  135.     ;; Second, insert lines between beginning and end of header lines, 
  136.     ;;    if any, or else insert the filename.
  137.     ;; Third, insert region.
  138.     
  139.     (save-excursion
  140.       (set-buffer input-buffer)
  141.       (save-excursion
  142.         (save-restriction
  143.           (widen)
  144.           (goto-char (point-min))
  145.           (let ((search-end (save-excursion (forward-line 100) (point))))
  146.             
  147.             ;; Find the filename or else explain that a filename is needed.
  148.             (or (search-forward "@setfilename" search-end t)
  149.                 (error
  150.                  "The texinfo file needs a line saying: @setfilename <name>"))
  151.             
  152.             ;; Find header and copy it into buffer; or copy just the 
  153.             ;;     filename if no header.
  154.             (goto-char (point-min))
  155.             (if (and 
  156.                  (prog1 
  157.                      (search-forward texinfo-start-of-header search-end t)
  158.                    (beginning-of-line)
  159.                    ;; Mark beginning of header.
  160.                    (setq filename-or-header-beginning (point)))
  161.                  (prog1 
  162.                      (search-forward texinfo-end-of-header nil t)
  163.                    (beginning-of-line)
  164.                    ;; Mark end of header
  165.                    (setq filename-or-header-end (point)))) 
  166.                 
  167.                 ;; Copy header  
  168.                 (setq filename-or-header 
  169.                       (buffer-substring
  170.                        (min filename-or-header-beginning region-beginning)
  171.                       filename-or-header-end))
  172.               ;; Else no header; insert @filename line in buffer
  173.               (goto-char (point-min))
  174.               (search-forward "@setfilename" search-end t)
  175.               (beginning-of-line)
  176.               (setq filename-or-header-beginning (point))
  177.               (forward-line 1)
  178.               (setq filename-or-header-end (point))
  179.               (setq filename-or-header 
  180.                     (buffer-substring 
  181.                      (min filename-or-header-beginning region-beginning)  
  182.                      filename-or-header-end)))))))
  183.     
  184.     ;; Insert the filename or header into the buffer.
  185.     (insert filename-or-header)
  186.     ;; Insert the region into the buffer.
  187.     (insert-buffer-substring
  188.      input-buffer
  189.      (max region-beginning filename-or-header-end)
  190.      region-ending)
  191.     ;; Make sure region ends in a newline.
  192.     (or (= (preceding-char) ?\n)
  193.         (insert "\n"))
  194.     
  195.     (texinfo-mode)
  196.     (setq fill-column fill-column-for-info)
  197.  
  198.     ;; Install a syntax table useful for scanning command operands.
  199.     (set-syntax-table texinfo-format-syntax-table)
  200.     ;; Append @refill to appropriate paragraphs
  201.     (goto-char (point-min))
  202.     (message "Converting region to Info format...")
  203.     (texinfo-append-refill)
  204.     ;; If the region includes the effective end of the data,
  205.     ;; discard everything after that.
  206.     (goto-char (point-max))
  207.     (if (re-search-backward "^@bye" nil t)
  208.         (delete-region (point) (point-max)))
  209.     ;; Make sure buffer ends in a newline.
  210.     (or (= (preceding-char) ?\n)
  211.         (insert "\n"))
  212.     ;; Don't use a previous value of texinfo-enclosure-list.
  213.     (setq texinfo-enclosure-list nil)
  214.  
  215.     ;; Now convert for real.
  216.     (goto-char (point-min))
  217.     (texinfo-format-scan)
  218.     (goto-char (point-min))
  219.     
  220.     (message "Done.")))
  221.  
  222.  
  223. ;;; Primary internal formatting function for the whole buffer.
  224.  
  225. (defun texinfo-format-buffer-1 ()
  226.   (let (texinfo-format-filename
  227.         texinfo-example-start
  228.         texinfo-command-start
  229.         texinfo-command-end
  230.         texinfo-command-name
  231.         texinfo-last-node
  232.         texinfo-last-node-pos
  233.         texinfo-vindex
  234.         texinfo-findex
  235.         texinfo-cindex
  236.         texinfo-pindex
  237.         texinfo-tindex
  238.         texinfo-kindex
  239.         texinfo-stack
  240.         texinfo-node-names
  241.     (texinfo-footnote-number 0)
  242.         last-input-buffer
  243.         outfile
  244.         (fill-column-for-info fill-column)
  245.         (input-buffer (current-buffer))
  246.         (input-directory default-directory))
  247.     (setq texinfo-enclosure-list nil)
  248.     (save-excursion
  249.       (goto-char (point-min))
  250.       (search-forward "@setfilename")
  251.       (setq texinfo-command-end (point))
  252.       (setq outfile (texinfo-parse-line-arg)))
  253.     (find-file outfile)
  254.     (texinfo-mode)
  255.     (setq fill-column fill-column-for-info)
  256.     (set-syntax-table texinfo-format-syntax-table)
  257.     (erase-buffer)
  258.     (insert-buffer-substring input-buffer)
  259.     ;; Append @refill to appropriate paragraphs
  260.     (goto-char (point-min))
  261.     (message "Converting %s to Info format..." (buffer-name input-buffer))
  262.     (texinfo-append-refill)
  263.     (goto-char (point-min))
  264.     (search-forward "@setfilename")
  265.     (beginning-of-line)
  266.     (delete-region (point-min) (point))
  267.     ;; Remove @bye at end of file, if it is there.
  268.     (goto-char (point-max))
  269.     (if (search-backward "@bye" nil t)
  270.         (delete-region (point) (point-max)))
  271.     ;; Make sure buffer ends in a newline.
  272.     (or (= (preceding-char) ?\n)
  273.         (insert "\n"))
  274.     ;; Scan the whole buffer, converting to Info format.
  275.     (texinfo-format-scan)
  276.     ;; Return data for indices.
  277.     (goto-char (point-min))
  278.     (list outfile
  279.           texinfo-vindex texinfo-findex texinfo-cindex
  280.           texinfo-pindex texinfo-tindex texinfo-kindex)))
  281.  
  282.  
  283. ;;; Perform non-@-command file conversions
  284.  
  285. (defun texinfo-format-convert (min max)
  286.   ;; Convert left and right quotes to typewriter font quotes.
  287.   (goto-char min)
  288.   (while (search-forward "``" max t)
  289.     (replace-match "\""))
  290.   (goto-char min)
  291.   (while (search-forward "''" max t)
  292.     (replace-match "\""))
  293.   ;; Convert three hyphens in a row to two.
  294.   (goto-char min)
  295.   (while (re-search-forward "\\( \\|\\w\\)\\(---\\)\\( \\|\\w\\)" max t)
  296.     (delete-region (1+ (match-beginning 2)) (+ 2 (match-beginning
  297.     2)))))
  298.  
  299. (defvar texinfo-no-refill-regexp
  300.   "^@\\(example\\|smallexample\\|lisp\\|smalllisp\\|display\\|format\\|flushleft\\|flushright\\|menu\\|titlepage\\|iftex\\|tex\\)"
  301.   "Regexp specifying environments in which paragraphs are not filled.")
  302.  
  303. (defvar texinfo-part-of-para-regexp
  304.   "^@\\(b{\\|bullet{\\|cite{\\|code{\\|emph{\\|equiv{\\|error{\\|expansion{\\|file{\\|i{\\|inforef{\\|kbd{\\|key{\\|lisp{\\|minus{\\|point{\\|print{\\|pxref{\\|r{\\|ref{\\|result{\\|samp{\\|sc{\\|t{\\|TeX{\\|today{\\|var{\\|w{\\|xref{\\)"
  305.   "Regexp specifying @-commands found within paragraphs.")
  306.  
  307. (defun texinfo-append-refill ()
  308.   "Append @refill at end of each paragraph that should be filled.
  309. Do not append @refill to paragraphs within @example and similar environments.  
  310. Do not append @refill to paragraphs containing @w{TEXT} or @*."
  311.  
  312.   ;; It is necessary to append @refill before other processing because
  313.   ;; the other processing removes information that tells Texinfo
  314.   ;; whether the text should or should not be filled.
  315.   
  316.   (while (< (point) (point-max))
  317.     (let ((refill-blank-lines "^[ \t\n]*$")
  318.           (case-fold-search nil))       ; Don't confuse @TeX and @tex....
  319.       (beginning-of-line)
  320.       ;; 1. Skip over blank lines;
  321.       ;;    skip over lines beginning with @-commands, 
  322.       ;;    but do not skip over lines
  323.       ;;      that are no-refill environments such as @example or
  324.       ;;      that begin with within-paragraph @-commands such as @code.
  325.       (while (and (looking-at (concat "^@\\|^\\\\\\|" refill-blank-lines))
  326.                   (not (looking-at 
  327.                         (concat
  328.                          "\\(" 
  329.                          texinfo-no-refill-regexp
  330.                          "\\|" 
  331.                          texinfo-part-of-para-regexp
  332.                          "\\)")))
  333.                   (< (point) (point-max)))
  334.         (forward-line 1))
  335.       ;; 2. Skip over @example and similar no-refill environments.
  336.       (if (looking-at texinfo-no-refill-regexp)
  337.           (let ((environment
  338.                  (buffer-substring (match-beginning 1) (match-end 1))))
  339.             (progn (re-search-forward (concat "^@end " environment) nil t)
  340.                    (forward-line 1)))
  341.         ;; 3. Do not refill a paragraph containing @w or @*
  342.         (if  (or
  343.               (>= (point) (point-max))
  344.               (re-search-forward
  345.                "@w{\\|@\\*" (save-excursion (forward-paragraph) (point)) t))
  346.             ;; Go to end of paragraph and do nothing.
  347.             (forward-paragraph) 
  348.           ;; 4. Else go to end of paragraph and insert @refill
  349.           (forward-paragraph)
  350.           (forward-line -1)
  351.           (end-of-line)
  352.           (delete-region
  353.            (point)
  354.            (save-excursion (skip-chars-backward " \t") (point)))
  355.           ;; `looking-at-backward' not available in v. 18.57
  356.           ;; (if (not (looking-at-backward "@refill\\|@bye")) ;)
  357.           (if (not (re-search-backward
  358.                     "@refill\\|@bye"
  359.                     (save-excursion (beginning-of-line) (point))
  360.                     t))
  361.               (insert "@refill"))
  362.           (forward-line 1))))))
  363.  
  364.  
  365. ;;; Perform those texinfo-to-info conversions that apply to the whole input
  366. ;;; uniformly.
  367.  
  368. (defun texinfo-format-scan ()
  369.   (texinfo-format-convert (point-min) (point-max))
  370.   ;; Scan for @-commands.
  371.   (goto-char (point-min))
  372.   (while (search-forward "@" nil t)
  373.     (if (looking-at "[@{}'` *]")
  374.         ;; Handle a few special @-followed-by-one-char commands.
  375.         (if (= (following-char) ?*)
  376.             (progn
  377.               ;; remove command
  378.               (delete-region (1- (point)) (1+ (point)))
  379.               ;; insert return if not at end of line;
  380.               ;; else line is already broken.
  381.               (if (not (= (following-char) ?\n))
  382.                   (insert ?\n)))      
  383.           ;; The other characters are simply quoted.  Delete the @.
  384.           (delete-char -1)
  385.           (forward-char 1))
  386.       ;; @ is followed by a command-word; find the end of the word.
  387.       (setq texinfo-command-start (1- (point)))
  388.       (if (= (char-syntax (following-char)) ?w)
  389.           (forward-word 1)
  390.         (forward-char 1))
  391.       (setq texinfo-command-end (point))
  392.       ;; Call the handler for this command.
  393.       (setq texinfo-command-name
  394.             (intern (buffer-substring
  395.              (1+ texinfo-command-start) texinfo-command-end)))
  396.       (let ((enclosure-type
  397.              (assoc
  398.               (symbol-name texinfo-command-name)
  399.               texinfo-enclosure-list)))
  400.         (if enclosure-type
  401.             (progn
  402.               (insert
  403.                (car (car (cdr enclosure-type))) 
  404.                (texinfo-parse-arg-discard)
  405.                (car (cdr (car (cdr enclosure-type)))))
  406.               (goto-char texinfo-command-start))
  407.           (let ((cmd (get texinfo-command-name 'texinfo-format)))
  408.             (if cmd (funcall cmd) (texinfo-unsupported)))))))
  409.   
  410.   (cond (texinfo-stack
  411.          (goto-char (nth 2 (car texinfo-stack)))
  412.          (error "Unterminated @%s" (car (car texinfo-stack))))))
  413.  
  414. (put 'begin 'texinfo-format 'texinfo-format-begin)
  415. (defun texinfo-format-begin ()
  416.   (texinfo-format-begin-end 'texinfo-format))
  417.  
  418. (put 'end 'texinfo-format 'texinfo-format-end)
  419. (defun texinfo-format-end ()
  420.   (texinfo-format-begin-end 'texinfo-end))
  421.  
  422. (defun texinfo-format-begin-end (prop)
  423.   (setq texinfo-command-name (intern (texinfo-parse-line-arg)))
  424.   (setq cmd (get texinfo-command-name prop))
  425.   (if cmd (funcall cmd)
  426.     (texinfo-unsupported)))
  427.  
  428. ;;; Parsing functions
  429.  
  430. (defun texinfo-parse-line-arg ()
  431.   (goto-char texinfo-command-end)
  432.   (let ((start (point)))
  433.     (cond ((looking-at " ")
  434.        (skip-chars-forward " ")
  435.        (setq start (point))
  436.        (end-of-line)
  437.            (skip-chars-backward " ")
  438.            (delete-region (point) (progn (end-of-line) (point)))
  439.        (setq texinfo-command-end (1+ (point))))
  440.       ((looking-at "{")
  441.        (setq start (1+ (point)))
  442.        (forward-list 1)
  443.        (setq texinfo-command-end (point))
  444.        (forward-char -1))
  445.       (t
  446.        (error "Invalid texinfo command arg format")))
  447.     (prog1 (buffer-substring start (point))
  448.        (if (eolp) (forward-char 1)))))
  449.  
  450. (defun texinfo-parse-expanded-arg ()
  451.   (goto-char texinfo-command-end)
  452.   (let ((start (point))
  453.     marker)
  454.     (cond ((looking-at " ")
  455.        (skip-chars-forward " ")
  456.        (setq start (point))
  457.        (end-of-line)
  458.        (setq texinfo-command-end (1+ (point))))
  459.       ((looking-at "{")
  460.        (setq start (1+ (point)))
  461.        (forward-list 1)
  462.        (setq texinfo-command-end (point))
  463.        (forward-char -1))
  464.       (t
  465.        (error "Invalid texinfo command arg format")))
  466.     (setq marker (move-marker (make-marker) texinfo-command-end))
  467.     (texinfo-format-expand-region start (point))
  468.     (setq texinfo-command-end (marker-position marker))
  469.     (move-marker marker nil)
  470.     (prog1 (buffer-substring start (point))
  471.        (if (eolp) (forward-char 1)))))
  472.  
  473. (defun texinfo-format-expand-region (start end)
  474.   (save-restriction
  475.     (narrow-to-region start end)
  476.     (let (texinfo-command-start
  477.       texinfo-command-end
  478.       texinfo-command-name
  479.       texinfo-stack)
  480.       (texinfo-format-scan))
  481.     (goto-char (point-max))))
  482.  
  483. (defun texinfo-parse-arg-discard ()
  484.   (prog1 (texinfo-parse-line-arg)
  485.      (texinfo-discard-command)))
  486.  
  487. (defun texinfo-discard-command ()
  488.   (delete-region texinfo-command-start texinfo-command-end))
  489.  
  490. (defun texinfo-optional-braces-discard ()
  491.   "Discard braces following command, if any."
  492.   (goto-char texinfo-command-end)
  493.   (let ((start (point)))
  494.     (cond ((looking-at "[ \t]*\n"))     ; do nothing
  495.           ((looking-at "{")             ; remove braces, if any
  496.        (forward-list 1)
  497.        (setq texinfo-command-end (point)))
  498.       (t
  499.            (error
  500.             "Invalid `texinfo-optional-braces-discard' format \(need braces?\)")))
  501.     (delete-region texinfo-command-start texinfo-command-end)))
  502.  
  503. (defun texinfo-format-parse-line-args ()
  504.   (let ((start (1- (point)))
  505.     next beg end
  506.     args)
  507.     (skip-chars-forward " ")
  508.     (while (not (eolp))
  509.       (setq beg (point))
  510.       (re-search-forward "[\n,]")
  511.       (setq next (point))
  512.       (if (bolp) (setq next (1- next)))
  513.       (forward-char -1)
  514.       (skip-chars-backward " ")
  515.       (setq end (point))
  516.       (setq args (cons (if (> end beg) (buffer-substring beg end))
  517.                args))
  518.       (goto-char next)
  519.       (skip-chars-forward " "))
  520.     (if (eolp) (forward-char 1))
  521.     (setq texinfo-command-end (point))
  522.     (nreverse args)))
  523.  
  524. (defun texinfo-format-parse-args ()
  525.   (let ((start (1- (point)))
  526.     next beg end
  527.     args)
  528.     (search-forward "{")
  529.     (save-excursion
  530.       (texinfo-format-expand-region 
  531.        (point)
  532.        (save-excursion (up-list 1) (1- (point)))))
  533.     ;; The following does not handle cross references of the form:
  534.     ;; `@xref{bullet, , @code{@@bullet}@{@}}.' because the
  535.     ;; re-search-forward finds the first right brace after the second
  536.     ;; comma. 
  537.     (while (/= (preceding-char) ?\})
  538.       (skip-chars-forward " \t\n")
  539.       (setq beg (point))
  540.       (re-search-forward "[},]")
  541.       (setq next (point))
  542.       (forward-char -1)
  543.       (skip-chars-backward " \t\n")
  544.       (setq end (point))
  545.       (cond ((< beg end)
  546.          (goto-char beg)
  547.          (while (search-forward "\n" end t)
  548.            (replace-match " "))))
  549.       (setq args (cons (if (> end beg) (buffer-substring beg end))
  550.                args))
  551.       (goto-char next))
  552.     (if (eolp) (forward-char 1))
  553.     (setq texinfo-command-end (point))
  554.     (nreverse args)))
  555.  
  556. (defun texinfo-format-parse-defun-args ()
  557.   (goto-char texinfo-command-end)
  558.   (let ((start (point)))
  559.     (end-of-line)
  560.     (setq texinfo-command-end (1+ (point)))
  561.     (let ((marker (move-marker (make-marker) texinfo-command-end)))
  562.       (texinfo-format-expand-region start (point))
  563.       (setq texinfo-command-end (marker-position marker))
  564.       (move-marker marker nil))
  565.     (goto-char start)
  566.     (let ((args '())
  567.       beg end)
  568.       (skip-chars-forward " ")
  569.       (while (not (eolp))
  570.     (cond ((looking-at "{")
  571.            (setq beg (1+ (point)))
  572.            (forward-list 1)
  573.            (setq end (1- (point))))
  574.           (t
  575.            (setq beg (point))
  576.            (re-search-forward "[\n ]")
  577.            (forward-char -1)
  578.            (setq end (point))))
  579.     (setq args (cons (buffer-substring beg end) args))
  580.     (skip-chars-forward " "))
  581.       (forward-char 1)
  582.       (nreverse args))))
  583.  
  584. (defun texinfo-discard-line ()
  585.   (goto-char texinfo-command-end)
  586.   (skip-chars-forward " \t")
  587.   (or (eolp)
  588.       (error "Extraneous text at end of command line."))
  589.   (goto-char texinfo-command-start)
  590.   (or (bolp)
  591.       (error "Extraneous text at beginning of command line."))
  592.   (delete-region (point) (progn (forward-line 1) (point))))
  593.  
  594. (defun texinfo-discard-line-with-args ()
  595.   (goto-char texinfo-command-start)
  596.   (delete-region (point) (progn (forward-line 1) (point))))
  597.  
  598.  
  599. ;;; @setfilename
  600.  
  601. ; 19 October 1990
  602. ; @setfilename modifed to work with include files; see @include
  603. ; (defun texinfo-format-setfilename ()
  604. ;   (let ((arg (texinfo-parse-arg-discard)))
  605. ;     (setq texinfo-format-filename
  606. ;       (file-name-nondirectory (expand-file-name arg)))
  607. ;     (insert "Info file: "
  608. ;         texinfo-format-filename ",    -*-Text-*-\n"
  609. ;         "produced by texinfo-format-buffer\nfrom "
  610. ;         (if (buffer-file-name input-buffer)
  611. ;         (concat "file: "
  612. ;             (file-name-sans-versions
  613. ;              (file-name-nondirectory
  614. ;               (buffer-file-name input-buffer))))
  615. ;           (concat "buffer " (buffer-name input-buffer)))
  616. ;         "\n\n")))
  617.  
  618. (put 'setfilename 'texinfo-format 'texinfo-format-setfilename)
  619. (defun texinfo-format-setfilename ()
  620.   (let ((arg (texinfo-parse-arg-discard)))
  621.     (if (eq input-buffer last-input-buffer)
  622.     nil                ; only use first setfilename in buffer
  623.       (message "Formatting Info file: %s" arg)
  624.       (setq texinfo-format-filename
  625.         (file-name-nondirectory (expand-file-name arg)))
  626.       (insert "Info file: "
  627.           texinfo-format-filename ",    -*-Text-*-\n"
  628.  
  629.           "produced on "
  630.               (substring (current-time-string) 8 10) " "
  631.               (substring (current-time-string) 4 7) " "
  632.               (substring (current-time-string) -4) 
  633.               " by texinfo-format-buffer"
  634.               "\nfrom "
  635.           (if (buffer-file-name input-buffer)
  636.           (concat "file `"
  637.               (file-name-sans-versions
  638.                (file-name-nondirectory
  639.                 (buffer-file-name input-buffer)))
  640.                           "'")
  641.         (concat "buffer `" (buffer-name input-buffer) "'"))
  642.               "\nusing `texinfmt.el' version "
  643.               texinfmt-version
  644.           ".\n\n"))))
  645.  
  646. ;;; @node, @menu
  647.  
  648. (put 'node 'texinfo-format 'texinfo-format-node)
  649. (defun texinfo-format-node ()
  650.   (let* ((args (texinfo-format-parse-line-args))
  651.      (name (nth 0 args))
  652.      (next (nth 1 args))
  653.      (prev (nth 2 args))
  654.      (up (nth 3 args)))
  655.     (texinfo-discard-command)
  656.     (setq texinfo-last-node name)
  657.     (let ((tem (downcase name)))
  658.       (if (assoc tem texinfo-node-names)
  659.       (error "Duplicate node name: %s" name)
  660.     (setq texinfo-node-names (cons (list tem) texinfo-node-names))))
  661.     (setq texinfo-footnote-number 0)
  662.     (or (bolp)
  663.     (insert ?\n))
  664.     (insert "\^_\nFile: " texinfo-format-filename
  665.         ", Node: " name)
  666.     (if next
  667.     (insert ", Next: " next))
  668.     (if prev
  669.     (insert ", Prev: " prev))
  670.     (if up
  671.     (insert ", Up: " up))
  672.     (insert ?\n)
  673.     (setq texinfo-last-node-pos (point))))
  674.  
  675. (put 'menu 'texinfo-format 'texinfo-format-menu)
  676. (defun texinfo-format-menu ()
  677.   (texinfo-discard-line)
  678.   (insert "* Menu:\n\n"))
  679.  
  680. (put 'menu 'texinfo-end 'texinfo-discard-command)
  681.  
  682.  
  683. ;;; Cross references
  684.  
  685. ; @xref {NODE, FNAME, NAME, FILE, DOCUMENT}
  686. ; -> *Note FNAME: (FILE)NODE
  687. ;   If FILE is missing,
  688. ;    *Note FNAME: NODE
  689. ;   If FNAME is empty and NAME is present
  690. ;    *Note NAME: Node
  691. ;   If both NAME and FNAME are missing
  692. ;    *Note NODE::
  693. ;   texinfo ignores the DOCUMENT argument.
  694. ; -> See section <xref to NODE> [NAME, else NODE], page <xref to NODE>
  695. ;   If FILE is specified, (FILE)NODE is used for xrefs.
  696. ;   If fifth argument DOCUMENT is specified, produces
  697. ;    See section <xref to NODE> [NAME, else NODE], page <xref to NODE>
  698. ;    of DOCUMENT
  699.  
  700. ; @ref             a reference that does not put `See' or `see' in
  701. ;                  the hardcopy and is the same as @xref in Info
  702. (put 'ref 'texinfo-format 'texinfo-format-xref)
  703.  
  704. (put 'xref 'texinfo-format 'texinfo-format-xref)
  705. (defun texinfo-format-xref ()
  706.   (let ((args (texinfo-format-parse-args)))
  707.     (texinfo-discard-command)
  708.     (insert "*Note ")
  709.     (let ((fname (or (nth 1 args) (nth 2 args))))
  710.       (if (null (or fname (nth 3 args)))
  711.       (insert (car args) "::")
  712.     (insert (or fname (car args)) ": ")
  713.     (if (nth 3 args)
  714.         (insert "(" (nth 3 args) ")"))
  715.     (insert (car args))))))
  716.  
  717. (put 'pxref 'texinfo-format 'texinfo-format-pxref)
  718. (defun texinfo-format-pxref ()
  719.   (texinfo-format-xref)
  720.   (or (save-excursion
  721.     (forward-char -2)
  722.     (looking-at "::"))
  723.       (insert ".")))
  724.  
  725. ;@inforef{NODE, FNAME, FILE}
  726. ;Like @xref{NODE, FNAME,,FILE} in texinfo.
  727. ;In Tex, generates "See Info file FILE, node NODE"
  728. (put 'inforef 'texinfo-format 'texinfo-format-inforef)
  729. (defun texinfo-format-inforef ()
  730.   (let ((args (texinfo-format-parse-args)))
  731.     (texinfo-discard-command)
  732.     (if (nth 1 args)
  733.         (insert "*Note " (nth 1 args) ": (" (nth 2 args) ")" (car args))
  734.       (insert "*Note " "(" (nth 2 args) ")" (car args) "::"))))
  735.  
  736.  
  737. ;;; Section headings
  738.  
  739. (put 'majorheading 'texinfo-format 'texinfo-format-chapter)
  740. (put 'chapheading 'texinfo-format 'texinfo-format-chapter)
  741. (put 'ichapter 'texinfo-format 'texinfo-format-chapter)
  742. (put 'chapter 'texinfo-format 'texinfo-format-chapter)
  743. (put 'iappendix 'texinfo-format 'texinfo-format-chapter)
  744. (put 'appendix 'texinfo-format 'texinfo-format-chapter)
  745. (put 'iunnumbered 'texinfo-format 'texinfo-format-chapter)
  746. (put 'top 'texinfo-format 'texinfo-format-chapter)
  747. (put 'unnumbered 'texinfo-format 'texinfo-format-chapter)
  748. (defun texinfo-format-chapter ()
  749.   (texinfo-format-chapter-1 ?*))
  750.  
  751. (put 'heading 'texinfo-format 'texinfo-format-section)
  752. (put 'isection 'texinfo-format 'texinfo-format-section)
  753. (put 'section 'texinfo-format 'texinfo-format-section)
  754. (put 'iappendixsection 'texinfo-format 'texinfo-format-section)
  755. (put 'appendixsection 'texinfo-format 'texinfo-format-section)
  756. (put 'iappendixsec 'texinfo-format 'texinfo-format-section)
  757. (put 'appendixsec 'texinfo-format 'texinfo-format-section)
  758. (put 'iunnumberedsec 'texinfo-format 'texinfo-format-section)
  759. (put 'unnumberedsec 'texinfo-format 'texinfo-format-section)
  760. (defun texinfo-format-section ()
  761.   (texinfo-format-chapter-1 ?=))
  762.  
  763. (put 'subheading 'texinfo-format 'texinfo-format-subsection)
  764. (put 'isubsection 'texinfo-format 'texinfo-format-subsection)
  765. (put 'subsection 'texinfo-format 'texinfo-format-subsection)
  766. (put 'iappendixsubsec 'texinfo-format 'texinfo-format-subsection)
  767. (put 'appendixsubsec 'texinfo-format 'texinfo-format-subsection)
  768. (put 'iunnumberedsubsec 'texinfo-format 'texinfo-format-subsection)
  769. (put 'unnumberedsubsec 'texinfo-format 'texinfo-format-subsection)
  770. (defun texinfo-format-subsection ()
  771.   (texinfo-format-chapter-1 ?-))
  772.  
  773. (put 'subsubheading 'texinfo-format 'texinfo-format-subsubsection)
  774. (put 'isubsubsection 'texinfo-format 'texinfo-format-subsubsection)
  775. (put 'subsubsection 'texinfo-format 'texinfo-format-subsubsection)
  776. (put 'iappendixsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
  777. (put 'appendixsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
  778. (put 'iunnumberedsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
  779. (put 'unnumberedsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
  780. (defun texinfo-format-subsubsection ()
  781.   (texinfo-format-chapter-1 ?.))
  782.  
  783. (defun texinfo-format-chapter-1 (belowchar)
  784.   (let ((arg (texinfo-parse-arg-discard)))
  785.     (message "Formatting: %s ... " arg)   ; So we can see where we are.
  786.     (insert ?\n arg ?\n "@SectionPAD " belowchar ?\n)
  787.     (forward-line -2)))
  788.  
  789. (put 'SectionPAD 'texinfo-format 'texinfo-format-sectionpad)
  790. (defun texinfo-format-sectionpad ()
  791.   (let ((str (texinfo-parse-arg-discard)))
  792.     (forward-char -1)
  793.     (let ((column (current-column)))
  794.       (forward-char 1)
  795.       (while (> column 0)
  796.     (insert str)
  797.     (setq column (1- column))))
  798.     (insert ?\n)))
  799.  
  800.  
  801. ;;; Space controling commands:  @. and @:   
  802. (put '\. 'texinfo-format 'texinfo-format-\.)
  803. (defun texinfo-format-\. ()
  804.   (texinfo-discard-command)
  805.   (insert "."))
  806.  
  807. (put '\: 'texinfo-format 'texinfo-format-\:)
  808. (defun texinfo-format-\: ()
  809.   (texinfo-discard-command))
  810.  
  811.  
  812. ;;; @center, @sp, and @br
  813.  
  814. (put 'center 'texinfo-format 'texinfo-format-center)
  815. (defun texinfo-format-center ()
  816.   (let ((arg (texinfo-parse-expanded-arg)))
  817.     (texinfo-discard-command)
  818.     (insert arg)
  819.     (insert ?\n)
  820.     (save-restriction
  821.       (goto-char (1- (point)))
  822.       (let ((indent-tabs-mode nil))
  823.     (center-line)))))
  824.  
  825. (put 'sp 'texinfo-format 'texinfo-format-sp)
  826. (defun texinfo-format-sp ()
  827.   (let* ((arg (texinfo-parse-arg-discard))
  828.      (num (read arg)))
  829.     (insert-char ?\n num)))
  830.  
  831. (put 'br 'texinfo-format 'texinfo-format-paragraph-break)
  832. (defun texinfo-format-paragraph-break ()
  833.   "Force a paragraph break.
  834. If used within a line, follow `@br' with braces."
  835.   (texinfo-optional-braces-discard)
  836.   ;; insert one return if at end of line;
  837.   ;; else insert two returns, to generate a blank line.
  838.   (if (= (following-char) ?\n)
  839.       (insert ?\n)
  840.     (insert-char ?\n 2)))
  841.  
  842.  
  843. ;;; @footnote  and  @footnotestyle
  844.  
  845. ; In Texinfo, footnotes are created with the `@footnote' command.
  846. ; This command is followed immediately by a left brace, then by the text of
  847. ; the footnote, and then by a terminating right brace.  The
  848. ; template for a footnote is:
  849. ;      @footnote{TEXT}
  850. ;
  851. ; Info has two footnote styles:
  852. ;    * In the End of node style, all the footnotes for a single node
  853. ;      are placed at the end of that node.  The footnotes are
  854. ;      separated from the rest of the node by a line of dashes with
  855. ;      the word `Footnotes' within it.
  856. ;    * In the Separate node style, all the footnotes for a single node
  857. ;      are placed in an automatically constructed node of their own.
  858.  
  859. ; Footnote style is specified by the @footnotestyle command, either
  860. ;    @footnotestyle separate
  861. ; or
  862. ;    @footnotestyle end
  863. ; The default is  separate
  864.  
  865. (defvar texinfo-footnote-style "separate" 
  866.   "Footnote style, either separate or end.")
  867.  
  868. (put 'footnotestyle 'texinfo-format 'texinfo-footnotestyle)
  869. (defun texinfo-footnotestyle ()
  870.   "Specify whether footnotes are at end of node or in separate nodes.
  871. Argument is either end or separate."
  872.   (setq texinfo-footnote-style (texinfo-parse-arg-discard)))
  873.  
  874. (defvar texinfo-footnote-number)
  875.  
  876. (put 'footnote 'texinfo-format 'texinfo-format-footnote)
  877. (defun texinfo-format-footnote ()
  878.   "Format a footnote in either end of node or separate node style.
  879. The   texinfo-footnote-style  variable controls which style is used."
  880.   (setq texinfo-footnote-number (1+ texinfo-footnote-number))
  881.   (cond ((string= texinfo-footnote-style "end")
  882.          (texinfo-format-end-node))
  883.         ((string= texinfo-footnote-style "separate")
  884.          (texinfo-format-separate-node))))
  885.  
  886. (defun texinfo-format-separate-node ()
  887.   "Format footnote in Separate node style, with notes in own node.
  888. The node is constructed automatically."
  889.   (let* (start
  890.          (arg (texinfo-parse-line-arg))
  891.          (node-name-beginning
  892.           (save-excursion
  893.             (re-search-backward
  894.              "^File: \\w+\\(\\w\\|\\s_\\|\\.\\|,\\)*[ \t]+Node:")
  895.             (match-end 0)))
  896.          (node-name
  897.           (save-excursion
  898.             (buffer-substring
  899.              (progn (goto-char node-name-beginning) ; skip over node command
  900.                     (skip-chars-forward " \t")  ; and over spaces
  901.                     (point))
  902.              (if (search-forward
  903.                   ","
  904.                   (save-excursion (end-of-line) (point)) t) ; bound search
  905.                  (1- (point))
  906.                (end-of-line) (point))))))
  907.     (texinfo-discard-command)  ; remove or insert whitespace, as needed
  908.     (delete-region (save-excursion (skip-chars-backward " \t\n") (point))
  909.                    (point))
  910.     (insert (format " (%d) (*Note %s-Footnotes::)"
  911.             texinfo-footnote-number node-name))
  912.     (fill-paragraph nil)
  913.     (save-excursion
  914.     (if (re-search-forward "^@node" nil 'move)
  915.         (forward-line -1))
  916.  
  917.     ;; two cases: for the first footnote, we must insert a node header;
  918.     ;; for the second and subsequent footnotes, we need only insert 
  919.     ;; the text of the  footnote.
  920.  
  921.     (if (save-excursion
  922.          (re-search-backward
  923.           (concat node-name "-Footnotes, Up: ")
  924.           node-name-beginning
  925.           t))
  926.         (progn   ; already at least one footnote
  927.           (setq start (point))
  928.           (insert (format "\n(%d)  %s\n" texinfo-footnote-number arg))
  929.           (fill-region start (point)))
  930.       ;; else not yet a footnote
  931.       (insert "\n\^_\nFile: "  texinfo-format-filename
  932.               "  Node: " node-name "-Footnotes, Up: " node-name "\n")
  933.       (setq start (point))
  934.       (insert (format "\n(%d)  %s\n" texinfo-footnote-number arg))
  935.       (fill-region start (point))))))
  936.  
  937. (defun texinfo-format-end-node ()
  938.   "Format footnote in the End of node style, with notes at end of node."
  939.   (let (start
  940.         (arg (texinfo-parse-line-arg)))
  941.     (texinfo-discard-command)  ; remove or insert whitespace, as needed
  942.     (delete-region (save-excursion (skip-chars-backward " \t\n") (point))
  943.                    (point))
  944.     (insert (format " (%d) " texinfo-footnote-number))
  945.     (fill-paragraph nil)
  946.     (save-excursion
  947.       (if (search-forward "\n--------- Footnotes ---------\n" nil t)
  948.           (progn ; already have footnote, put new one before end of node
  949.             (if (re-search-forward "^@node" nil 'move)
  950.                 (forward-line -1))
  951.             (setq start (point))
  952.             (insert (format "\n(%d)  %s\n" texinfo-footnote-number arg))
  953.             (fill-region start (point)))
  954.         ;; else no prior footnote
  955.         (if (re-search-forward "^@node" nil 'move)
  956.             (forward-line -1))
  957.         (insert "\n--------- Footnotes ---------\n")
  958.         (setq start (point))
  959.         (insert (format "\n(%d)  %s\n" texinfo-footnote-number arg))))))
  960.  
  961.  
  962. ;;; @itemize, @enumerate, and similar commands
  963.  
  964. ;; @itemize pushes (itemize "COMMANDS" STARTPOS) on texinfo-stack.
  965. ;; @enumerate pushes (enumerate 0 STARTPOS).
  966. ;; @item dispatches to the texinfo-item prop of the first elt of the list.
  967. ;; For itemize, this puts in and rescans the COMMANDS.
  968. ;; For enumerate, this increments the number and puts it in.
  969. ;; In either case, it puts a Backspace at the front of the line
  970. ;; which marks it not to be indented later.
  971. ;; All other lines get indented by 5 when the @end is reached.
  972.  
  973. (defvar texinfo-stack-depth 0
  974.   "Count of number of unpopped texinfo-push-stack calls.
  975. Used by @refill indenting command to avoid indenting within lists, etc.")
  976.  
  977. (defun texinfo-push-stack (check arg)
  978.   (setq texinfo-stack-depth (1+ texinfo-stack-depth))
  979.   (setq texinfo-stack
  980.     (cons (list check arg texinfo-command-start)
  981.           texinfo-stack)))
  982.  
  983. (defun texinfo-pop-stack (check)
  984.   (setq texinfo-stack-depth (1- texinfo-stack-depth))
  985.   (if (null texinfo-stack)
  986.       (error "Unmatched @end %s" check))
  987.   (if (not (eq (car (car texinfo-stack)) check))
  988.       (error "@end %s matches @%s"
  989.          check (car (car texinfo-stack))))
  990.   (prog1 (cdr (car texinfo-stack))
  991.      (setq texinfo-stack (cdr texinfo-stack))))
  992.  
  993. (put 'itemize 'texinfo-format 'texinfo-itemize)
  994. (defun texinfo-itemize ()
  995.   (texinfo-push-stack
  996.    'itemize
  997.    (progn (skip-chars-forward " \t")
  998.           (if (eolp)
  999.               "@bullet"
  1000.             (texinfo-parse-line-arg))))
  1001.   (texinfo-discard-line-with-args)
  1002.   (setq fill-column (- fill-column 5)))
  1003.  
  1004. (put 'itemize 'texinfo-end 'texinfo-end-itemize)
  1005. (defun texinfo-end-itemize ()
  1006.   (setq fill-column (+ fill-column 5))
  1007.   (texinfo-discard-command)
  1008.   (let ((stacktop
  1009.      (texinfo-pop-stack 'itemize)))
  1010.     (texinfo-do-itemize (nth 1 stacktop))))
  1011.  
  1012. (put 'enumerate 'texinfo-format 'texinfo-enumerate)
  1013. (defun texinfo-enumerate ()
  1014.   (texinfo-push-stack
  1015.    'enumerate 
  1016.    (progn (skip-chars-forward " \t")
  1017.           (if (eolp)
  1018.               1
  1019.             (read (current-buffer)))))
  1020.   (if (and (symbolp (car (cdr (car texinfo-stack))))
  1021.            (> 1 (length (symbol-name (car (cdr (car texinfo-stack)))))))
  1022.       (error
  1023.        "@enumerate: Use a number or letter, eg: 1, A, a, 3, B, or d." ))
  1024.   (texinfo-discard-line-with-args)
  1025.   (setq fill-column (- fill-column 5)))
  1026.  
  1027. (put 'enumerate 'texinfo-end 'texinfo-end-enumerate)
  1028. (defun texinfo-end-enumerate ()
  1029.   (setq fill-column (+ fill-column 5))
  1030.   (texinfo-discard-command)
  1031.   (let ((stacktop
  1032.      (texinfo-pop-stack 'enumerate)))
  1033.     (texinfo-do-itemize (nth 1 stacktop))))
  1034.  
  1035. ;; @alphaenumerate never became a standard part of Texinfo
  1036. (put 'alphaenumerate 'texinfo-format 'texinfo-alphaenumerate)
  1037. (defun texinfo-alphaenumerate ()
  1038.   (texinfo-push-stack 'alphaenumerate (1- ?a))
  1039.   (setq fill-column (- fill-column 5))
  1040.   (texinfo-discard-line))
  1041.  
  1042. (put 'alphaenumerate 'texinfo-end 'texinfo-end-alphaenumerate)
  1043. (defun texinfo-end-alphaenumerate ()
  1044.   (setq fill-column (+ fill-column 5))
  1045.   (texinfo-discard-command)
  1046.   (let ((stacktop
  1047.      (texinfo-pop-stack 'alphaenumerate)))
  1048.     (texinfo-do-itemize (nth 1 stacktop))))
  1049.  
  1050. ;; @capsenumerate never became a standard part of Texinfo
  1051. (put 'capsenumerate 'texinfo-format 'texinfo-capsenumerate)
  1052. (defun texinfo-capsenumerate ()
  1053.   (texinfo-push-stack 'capsenumerate (1- ?A))
  1054.   (setq fill-column (- fill-column 5))
  1055.   (texinfo-discard-line))
  1056.  
  1057. (put 'capsenumerate 'texinfo-end 'texinfo-end-capsenumerate)
  1058. (defun texinfo-end-capsenumerate ()
  1059.   (setq fill-column (+ fill-column 5))
  1060.   (texinfo-discard-command)
  1061.   (let ((stacktop
  1062.      (texinfo-pop-stack 'capsenumerate)))
  1063.     (texinfo-do-itemize (nth 1 stacktop))))
  1064.  
  1065. ;; At the @end, indent all the lines within the construct
  1066. ;; except those marked with backspace.  FROM says where
  1067. ;; construct started.
  1068. (defun texinfo-do-itemize (from)
  1069.   (save-excursion
  1070.    (while (progn (forward-line -1)
  1071.          (>= (point) from))
  1072.      (if (= (following-char) ?\b)
  1073.      (save-excursion
  1074.        (delete-char 1)
  1075.        (end-of-line)
  1076.        (delete-char 6))
  1077.        (if (not (looking-at "[ \t]*$"))
  1078.        (save-excursion (insert "     ")))))))
  1079.  
  1080. (put 'item 'texinfo-format 'texinfo-item)
  1081. (put 'itemx 'texinfo-format 'texinfo-item)
  1082. (defun texinfo-item ()
  1083.   (funcall (get (car (car texinfo-stack)) 'texinfo-item)))
  1084.  
  1085. (put 'itemize 'texinfo-item 'texinfo-itemize-item)
  1086. (defun texinfo-itemize-item ()
  1087.   ;; (texinfo-discard-line)   ; Did not handle text on same line as @item.
  1088.   (delete-region (1+ (point)) (save-excursion (beginning-of-line) (point)))
  1089.   (if (looking-at "[ \t]*[^ \t\n]+")
  1090.       ;; Text on same line as @item command.
  1091.       (insert "\b   " (nth 1 (car texinfo-stack)) " \n")
  1092.     ;; Else text on next line.
  1093.     (insert "\b   " (nth 1 (car texinfo-stack)) " "))
  1094.   (forward-line -1))
  1095.  
  1096. (put 'enumerate 'texinfo-item 'texinfo-enumerate-item)
  1097. (defun texinfo-enumerate-item ()
  1098.   (texinfo-discard-line)
  1099.   (let (enumerating-symbol)
  1100.     (cond ((integerp (car (cdr (car texinfo-stack))))
  1101.            (setq enumerating-symbol (car (cdr (car texinfo-stack))))
  1102.            (insert ?\b (format "%3d. " enumerating-symbol) ?\n)
  1103.            (setcar (cdr (car texinfo-stack)) (1+ enumerating-symbol)))
  1104.           ((symbolp (car (cdr (car texinfo-stack))))
  1105.            (setq enumerating-symbol
  1106.                  (symbol-name (car (cdr (car texinfo-stack)))))
  1107.            (if (or (equal ?\[ (string-to-char enumerating-symbol))
  1108.                    (equal ?\{ (string-to-char enumerating-symbol)))
  1109.                (error
  1110.                 "Too many items in enumerated list; alphabet ends at Z."))
  1111.            (insert ?\b (format "%3s. " enumerating-symbol) ?\n)
  1112.            (setcar (cdr (car texinfo-stack))
  1113.                    (make-symbol
  1114.                     (char-to-string
  1115.                      (1+ 
  1116.                       (string-to-char enumerating-symbol))))))
  1117.           (t
  1118.           (error
  1119.            "@enumerate: Use a number or letter, eg: 1, A, a, 3, B or d." )))
  1120.     (forward-line -1)))
  1121.  
  1122. (put 'alphaenumerate 'texinfo-item 'texinfo-alphaenumerate-item)
  1123. (defun texinfo-alphaenumerate-item ()
  1124.   (texinfo-discard-line)
  1125.   (let ((next (1+ (car (cdr (car texinfo-stack))))))
  1126.     (if (> next ?z)
  1127.     (error "More than 26 items in @alphaenumerate; get a bigger alphabet."))
  1128.     (setcar (cdr (car texinfo-stack)) next)
  1129.     (insert "\b  " next ". \n"))
  1130.   (forward-line -1))
  1131.  
  1132. (put 'capsenumerate 'texinfo-item 'texinfo-capsenumerate-item)
  1133. (defun texinfo-capsenumerate-item ()
  1134.   (texinfo-discard-line)
  1135.   (let ((next (1+ (car (cdr (car texinfo-stack))))))
  1136.     (if (> next ?Z)
  1137.     (error "More than 26 items in @capsenumerate; get a bigger alphabet."))
  1138.     (setcar (cdr (car texinfo-stack)) next)
  1139.     (insert "\b  " next ". \n"))
  1140.   (forward-line -1))
  1141.  
  1142.  
  1143. ;;; @table
  1144.  
  1145. ; The `@table' command produces two-column tables.
  1146.  
  1147. (put 'table 'texinfo-format 'texinfo-table)
  1148. (defun texinfo-table ()
  1149.   (texinfo-push-stack 
  1150.    'table 
  1151.    (progn (skip-chars-forward " \t")
  1152.           (if (eolp)
  1153.               "@asis"
  1154.             (texinfo-parse-line-arg))))
  1155.   (texinfo-discard-line-with-args)
  1156.   (setq fill-column (- fill-column 5)))
  1157.  
  1158. (put 'table 'texinfo-item 'texinfo-table-item)
  1159. (defun texinfo-table-item ()
  1160.   (let ((arg (texinfo-parse-arg-discard))
  1161.     (itemfont (car (cdr (car texinfo-stack)))))
  1162.     (insert ?\b itemfont ?\{ arg "}\n     \n"))
  1163.   (forward-line -2))
  1164.  
  1165. (put 'table 'texinfo-end 'texinfo-end-table)
  1166. (defun texinfo-end-table ()
  1167.   (setq fill-column (+ fill-column 5))
  1168.   (texinfo-discard-command)
  1169.   (let ((stacktop
  1170.      (texinfo-pop-stack 'table)))
  1171.     (texinfo-do-itemize (nth 1 stacktop))))
  1172.  
  1173. ;; @description appears to be an undocumented variant on @table that
  1174. ;; does not require an arg.  It fails in texinfo.tex 2.58 and is not
  1175. ;; part of makeinfo.c   The command appears to be a relic of the past.
  1176. (put 'description 'texinfo-end 'texinfo-end-table)
  1177. (put 'description 'texinfo-format 'texinfo-description)
  1178. (defun texinfo-description ()
  1179.   (texinfo-push-stack 'table "@asis")
  1180.   (setq fill-column (- fill-column 5))
  1181.   (texinfo-discard-line))
  1182.  
  1183.  
  1184. ;;; @ftable, @vtable
  1185.  
  1186. ; The `@ftable' and `@vtable' commands are like the `@table' command
  1187. ; but they also insert each entry in the first column of the table
  1188. ; into the function or variable index.
  1189.  
  1190. ;; Handle the @ftable and @vtable commands:
  1191.  
  1192. (put 'ftable 'texinfo-format 'texinfo-ftable)
  1193. (put 'vtable 'texinfo-format 'texinfo-vtable)
  1194.  
  1195. (defun texinfo-ftable () (texinfo-indextable 'ftable))
  1196. (defun texinfo-vtable () (texinfo-indextable 'vtable))
  1197.  
  1198. (defun texinfo-indextable (table-type)
  1199.   (texinfo-push-stack table-type (texinfo-parse-arg-discard))
  1200.   (setq fill-column (- fill-column 5)))
  1201.  
  1202. ;; Handle the @item commands within ftable and vtable:
  1203.  
  1204. (put 'ftable 'texinfo-item 'texinfo-ftable-item)
  1205. (put 'vtable 'texinfo-item 'texinfo-vtable-item)
  1206.  
  1207. (defun texinfo-ftable-item () (texinfo-indextable-item 'texinfo-findex))
  1208. (defun texinfo-vtable-item () (texinfo-indextable-item 'texinfo-vindex))
  1209.  
  1210. (defun texinfo-indextable-item (index-type)
  1211.   (let ((item (texinfo-parse-arg-discard))
  1212.         (itemfont (car (cdr (car texinfo-stack))))
  1213.         (indexvar index-type))
  1214.     (insert ?\b itemfont ?\{ item "}\n     \n")
  1215.     (set indexvar
  1216.          (cons
  1217.           (list item texinfo-last-node)
  1218.           (symbol-value indexvar)))
  1219.     (forward-line -2)))
  1220.  
  1221. ;; Handle @end ftable, @end vtable
  1222.  
  1223. (put 'ftable 'texinfo-end 'texinfo-end-ftable)
  1224. (put 'vtable 'texinfo-end 'texinfo-end-vtable)
  1225.  
  1226. (defun texinfo-end-ftable () (texinfo-end-indextable 'ftable))
  1227. (defun texinfo-end-vtable () (texinfo-end-indextable 'vtable))
  1228.  
  1229. (defun texinfo-end-indextable (table-type)
  1230.   (setq fill-column (+ fill-column 5))
  1231.   (texinfo-discard-command)
  1232.   (let ((stacktop
  1233.          (texinfo-pop-stack table-type)))
  1234.     (texinfo-do-itemize (nth 1 stacktop))))
  1235.  
  1236.  
  1237. ;;; @ifinfo,  @iftex, @tex
  1238.  
  1239. (put 'ifinfo 'texinfo-format 'texinfo-discard-line)
  1240. (put 'ifinfo 'texinfo-end 'texinfo-discard-command)
  1241.  
  1242. (put 'iftex 'texinfo-format 'texinfo-format-iftex)
  1243. (defun texinfo-format-iftex ()
  1244.   (delete-region texinfo-command-start
  1245.          (progn (re-search-forward "@end iftex[ \t]*\n")
  1246.             (point))))
  1247.  
  1248. (put 'tex 'texinfo-format 'texinfo-format-tex)
  1249. (defun texinfo-format-tex ()
  1250.   (delete-region texinfo-command-start
  1251.          (progn (re-search-forward "@end tex[ \t]*\n")
  1252.             (point))))
  1253.  
  1254.  
  1255. ;;; @titlepage
  1256.  
  1257. (put 'titlepage 'texinfo-format 'texinfo-format-titlepage)
  1258. (defun texinfo-format-titlepage ()
  1259.   (delete-region texinfo-command-start
  1260.          (progn (re-search-forward "@end titlepage[ \t]*\n")
  1261.             (point))))
  1262.  
  1263. (put 'endtitlepage 'texinfo-format 'texinfo-discard-line)
  1264.  
  1265. ; @titlespec         an alternative titling command; ignored by Info
  1266.  
  1267. (put 'titlespec 'texinfo-format 'texinfo-format-titlespec)
  1268. (defun texinfo-format-titlespec ()
  1269.   (delete-region texinfo-command-start
  1270.                  (progn (re-search-forward "@end titlespec[ \t]*\n")
  1271.                         (point))))
  1272.  
  1273. (put 'endtitlespec 'texinfo-format 'texinfo-discard-line)
  1274.  
  1275.  
  1276. ;;; @today
  1277.  
  1278. (put 'today 'texinfo-format 'texinfo-format-today)
  1279.  
  1280. ; Produces Day Month Year style of output.  eg `1 Jan 1900'
  1281. ; The `@today{}' command requires a pair of braces, like `@dots{}'.
  1282. (defun texinfo-format-today ()
  1283.   (texinfo-parse-arg-discard)
  1284.   (insert (format "%s %s %s"
  1285.           (substring (current-time-string) 8 10)
  1286.           (substring (current-time-string) 4 7)
  1287.           (substring (current-time-string) -4))))
  1288.  
  1289.  
  1290. ;;; @ignore
  1291.  
  1292. (put 'ignore 'texinfo-format 'texinfo-format-ignore)
  1293. (defun texinfo-format-ignore ()
  1294.   (delete-region texinfo-command-start
  1295.          (progn (re-search-forward "@end ignore[ \t]*\n")
  1296.             (point))))
  1297.  
  1298. (put 'endignore 'texinfo-format 'texinfo-discard-line)
  1299.  
  1300.  
  1301. ;;; Define the Info enclosure command: @definfoenclose
  1302.  
  1303. ; A `@definfoenclose' command may be used to define a highlighting
  1304. ; command for Info, but not for TeX.  A command defined using
  1305. ; `@definfoenclose' marks text by enclosing it in strings that precede
  1306. ; and follow the text.
  1307. ; Presumably, if you define a command with `@definfoenclose` for Info,
  1308. ; you will also define the same command in the TeX definitions file,
  1309. ; `texinfo.tex' in a manner appropriate for typesetting.
  1310. ; Write a `@definfoenclose' command on a line and follow it with three
  1311. ; arguments separated by commas (commas are used as separators in an
  1312. ; `@node' line in the same way).  The first argument to
  1313. ; `@definfoenclose' is the @-command name \(without the `@'\); the
  1314. ; second argument is the Info start delimiter string; and the third
  1315. ; argument is the Info end delimiter string.  The latter two arguments
  1316. ; enclose the highlighted text in the Info file.  A delimiter string
  1317. ; may contain spaces.  Neither the start nor end delimiter is
  1318. ; required.  However, if you do not provide a start delimiter, you
  1319. ; must follow the command name with two commas in a row; otherwise,
  1320. ; the Info formatting commands will misinterpret the end delimiter
  1321. ; string as a start delimiter string.
  1322. ; An enclosure command defined this way takes one argument in braces.
  1323. ;
  1324. ; For example, you can write:
  1325. ;
  1326. ;     @ifinfo
  1327. ;     @definfoenclose phoo, //, \\
  1328. ;     @end ifinfo
  1329. ;
  1330. ; near the beginning of a Texinfo file at the beginning of the lines
  1331. ; to define `@phoo' as an Info formatting command that inserts `//'
  1332. ; before and `\\' after the argument to `@phoo'.  You can then write
  1333. ; `@phoo{bar}' wherever you want `//bar\\' highlighted in Info.
  1334. ;
  1335. ; Also, for TeX formatting, you could write 
  1336. ;
  1337. ;     @iftex
  1338. ;     @global@let@phoo=@i
  1339. ;     @end iftex
  1340. ;
  1341. ; to define `@phoo' as a command that causes TeX to typeset
  1342. ; the argument to `@phoo' in italics.
  1343. ;
  1344. ; Note that each definition applies to its own formatter: one for TeX,
  1345. ; the other for texinfo-format-buffer or texinfo-format-region.
  1346. ;
  1347. ; Here is another example: write
  1348. ;
  1349. ;     @definfoenclose headword, , :
  1350. ;
  1351. ; near the beginning of the file, to define `@headword' as an Info
  1352. ; formatting command that inserts nothing before and a colon after the
  1353. ; argument to `@headword'.
  1354.  
  1355. (put 'definfoenclose 'texinfo-format 'texinfo-define-info-enclosure)
  1356. (defun texinfo-define-info-enclosure ()
  1357.   (let* ((args (texinfo-format-parse-line-args))
  1358.      (command-name (nth 0 args))
  1359.      (beginning-delimiter (or (nth 1 args) ""))
  1360.      (end-delimiter (or (nth 2 args) "")))
  1361.     (texinfo-discard-command)
  1362.     (setq texinfo-enclosure-list
  1363.     (cons
  1364.      (list command-name
  1365.            (list
  1366.         beginning-delimiter
  1367.         end-delimiter))
  1368.      texinfo-enclosure-list))))
  1369.  
  1370.  
  1371. ;;; @var, @code and the like
  1372.  
  1373. (put 'var 'texinfo-format 'texinfo-format-var)
  1374. ;  @sc  a small caps font for TeX; formatted as `var' in Info
  1375. (put 'sc 'texinfo-format 'texinfo-format-var)
  1376. (defun texinfo-format-var ()
  1377.   (insert (upcase (texinfo-parse-arg-discard)))
  1378.   (goto-char texinfo-command-start))
  1379.  
  1380. ; various noops
  1381.  
  1382. (put 'b 'texinfo-format 'texinfo-format-noop)
  1383. (put 'i 'texinfo-format 'texinfo-format-noop)
  1384. (put 'r 'texinfo-format 'texinfo-format-noop)
  1385. (put 't 'texinfo-format 'texinfo-format-noop)
  1386. (put 'w 'texinfo-format 'texinfo-format-noop)
  1387. (put 'asis 'texinfo-format 'texinfo-format-noop)
  1388. (put 'dmn 'texinfo-format 'texinfo-format-noop)
  1389. (put 'key 'texinfo-format 'texinfo-format-noop)
  1390. (put 'math 'texinfo-format 'texinfo-format-noop)
  1391. (put 'titlefont 'texinfo-format 'texinfo-format-noop)
  1392. (defun texinfo-format-noop ()
  1393.   (insert (texinfo-parse-arg-discard))
  1394.   (goto-char texinfo-command-start))
  1395.  
  1396. (put 'cite 'texinfo-format 'texinfo-format-code)
  1397. (put 'code 'texinfo-format 'texinfo-format-code)
  1398. (put 'file 'texinfo-format 'texinfo-format-code)
  1399. (put 'kbd 'texinfo-format 'texinfo-format-code)
  1400. (put 'samp 'texinfo-format 'texinfo-format-code)
  1401. (defun texinfo-format-code ()
  1402.   (insert "`" (texinfo-parse-arg-discard) "'")
  1403.   (goto-char texinfo-command-start))
  1404.  
  1405. (put 'emph 'texinfo-format 'texinfo-format-emph)
  1406. (put 'strong 'texinfo-format 'texinfo-format-emph)
  1407. (defun texinfo-format-emph ()
  1408.   (insert "*" (texinfo-parse-arg-discard) "*")
  1409.   (goto-char texinfo-command-start))
  1410.  
  1411. (put 'dfn 'texinfo-format 'texinfo-format-defn)
  1412. (put 'defn 'texinfo-format 'texinfo-format-defn)
  1413. (defun texinfo-format-defn ()
  1414.   (insert "\"" (texinfo-parse-arg-discard) "\"")
  1415.   (goto-char texinfo-command-start))
  1416.  
  1417. (put 'bullet 'texinfo-format 'texinfo-format-bullet)
  1418. (defun texinfo-format-bullet ()
  1419.   "Insert an asterisk.
  1420. If used within a line, follow `@bullet' with braces."
  1421.   (texinfo-optional-braces-discard)
  1422.   (insert "*"))
  1423.  
  1424.  
  1425. ;;; @example, @lisp, @quotation, @display, @smalllisp, @smallexample
  1426.  
  1427. (put 'display 'texinfo-format 'texinfo-format-example)
  1428. (put 'example 'texinfo-format 'texinfo-format-example)
  1429. (put 'lisp 'texinfo-format 'texinfo-format-example)
  1430. (put 'quotation 'texinfo-format 'texinfo-format-example)
  1431. (put 'smallexample 'texinfo-format 'texinfo-format-example)
  1432. (put 'smalllisp 'texinfo-format 'texinfo-format-example)
  1433. (defun texinfo-format-example ()
  1434.   (texinfo-push-stack 'example nil)
  1435.   (setq fill-column (- fill-column 5))
  1436.   (texinfo-discard-line))
  1437.  
  1438. (put 'example 'texinfo-end 'texinfo-end-example)
  1439. (put 'display 'texinfo-end 'texinfo-end-example)
  1440. (put 'lisp 'texinfo-end 'texinfo-end-example)
  1441. (put 'quotation 'texinfo-end 'texinfo-end-example)
  1442. (put 'smallexample 'texinfo-end 'texinfo-end-example)
  1443. (put 'smalllisp 'texinfo-end 'texinfo-end-example)
  1444. (defun texinfo-end-example ()
  1445.   (setq fill-column (+ fill-column 5))
  1446.   (texinfo-discard-command)
  1447.   (let ((stacktop
  1448.      (texinfo-pop-stack 'example)))
  1449.     (texinfo-do-itemize (nth 1 stacktop))))
  1450.  
  1451. (put 'exdent 'texinfo-format 'texinfo-format-exdent)
  1452. (defun texinfo-format-exdent ()
  1453.   (texinfo-discard-command)
  1454.   (delete-region (point)
  1455.          (progn
  1456.           (skip-chars-forward " ")
  1457.           (point)))
  1458.   (insert ?\b)
  1459.   ;; Cancel out the deletion that texinfo-do-itemize
  1460.   ;; is going to do at the end of this line.
  1461.   (save-excursion
  1462.     (end-of-line)
  1463.     (insert "\n     ")))
  1464.  
  1465.  
  1466. ;;; @cartouche 
  1467.  
  1468. ; The @cartouche command is a noop in Info; in a printed manual,
  1469. ; it makes a box with rounded corners.
  1470.  
  1471. (put 'cartouche 'texinfo-format 'texinfo-discard-line)
  1472. (put 'cartouche 'texinfo-end 'texinfo-discard-command)
  1473.  
  1474.  
  1475. ;;; @flushleft and @format
  1476.  
  1477. ; The @flushleft command left justifies every line but leaves the
  1478. ; right end ragged.  As far as Info is concerned, @flushleft is a
  1479. ; `do-nothing' command
  1480.  
  1481. ; The @format command is similar to @example except that it does not
  1482. ; indent; this means that in Info, @format is similar to @flushleft.
  1483.  
  1484. (put 'format 'texinfo-format 'texinfo-format-flushleft)
  1485. (put 'flushleft 'texinfo-format 'texinfo-format-flushleft)
  1486. (defun texinfo-format-flushleft ()
  1487.   (texinfo-discard-line))
  1488.  
  1489. (put 'format 'texinfo-end 'texinfo-end-flushleft)
  1490. (put 'flushleft 'texinfo-end 'texinfo-end-flushleft)
  1491. (defun texinfo-end-flushleft ()
  1492.   (texinfo-discard-command))
  1493.  
  1494.  
  1495. ;;; @flushright
  1496.  
  1497. ; The @flushright command right justifies every line but leaves the
  1498. ; left end ragged.  Spaces and tabs at the right ends of lines are
  1499. ; removed so that visible text lines up on the right side.
  1500.  
  1501. (put 'flushright 'texinfo-format 'texinfo-format-flushright)
  1502. (defun texinfo-format-flushright ()
  1503.   (texinfo-push-stack 'flushright nil)
  1504.   (texinfo-discard-line))
  1505.  
  1506. (put 'flushright 'texinfo-end 'texinfo-end-flushright)
  1507. (defun texinfo-end-flushright ()
  1508.   (texinfo-discard-command)
  1509.  
  1510.   (let ((stacktop
  1511.          (texinfo-pop-stack 'flushright)))
  1512.  
  1513.     (texinfo-do-flushright (nth 1 stacktop))))
  1514.  
  1515. (defun texinfo-do-flushright (from)
  1516.   (save-excursion
  1517.    (while (progn (forward-line -1)
  1518.                  (>= (point) from))
  1519.  
  1520.      (beginning-of-line)
  1521.      (insert
  1522.       (make-string
  1523.        (- fill-column
  1524.           (save-excursion
  1525.             (end-of-line) 
  1526.             (skip-chars-backward " \t")
  1527.             (delete-region (point) (progn (end-of-line) (point)))
  1528.             (current-column)))  
  1529.        ? )))))
  1530.  
  1531.  
  1532. ;;; @ctrl, @TeX, @copyright, @minus, @dots
  1533.  
  1534. (put 'ctrl 'texinfo-format 'texinfo-format-ctrl)
  1535. (defun texinfo-format-ctrl ()
  1536.   (let ((str (texinfo-parse-arg-discard)))
  1537.     (insert (logand 31 (aref str 0)))))
  1538.  
  1539. (put 'TeX 'texinfo-format 'texinfo-format-TeX)
  1540. (defun texinfo-format-TeX ()
  1541.   (texinfo-parse-arg-discard)
  1542.   (insert "TeX"))
  1543.  
  1544. (put 'copyright 'texinfo-format 'texinfo-format-copyright)
  1545. (defun texinfo-format-copyright ()
  1546.   (texinfo-parse-arg-discard)
  1547.   (insert "(C)"))
  1548.  
  1549. (put 'minus 'texinfo-format 'texinfo-format-minus)
  1550. (defun texinfo-format-minus ()
  1551.   "Insert a minus sign.
  1552. If used within a line, follow `@minus' with braces."
  1553.   (texinfo-optional-braces-discard)
  1554.   (insert "-"))
  1555.  
  1556. (put 'dots 'texinfo-format 'texinfo-format-dots)
  1557. (defun texinfo-format-dots ()
  1558.   (texinfo-parse-arg-discard)
  1559.   (insert "..."))
  1560.  
  1561.  
  1562. ;;; Refilling and indenting:  @refill, @paragraphindent, @noindent
  1563.  
  1564. ;;; Indent only those paragraphs that are refilled as a result of an
  1565. ;;; @refill command.  
  1566.  
  1567. ;    * If the value is `asis', do not change the existing indentation at
  1568. ;      the starts of paragraphs.
  1569.  
  1570. ;    * If the value zero, delete any existing indentation.
  1571.  
  1572. ;    * If the value is greater than zero, indent each paragraph by that
  1573. ;      number of spaces.
  1574.  
  1575. ;;; But do not refill paragraphs with an @refill command that are
  1576. ;;; preceded by @noindent or are part of a table, list, or deffn.
  1577.  
  1578. (defvar texinfo-paragraph-indent "asis"
  1579.   "Number of spaces for @refill to indent a paragraph; else to leave as is.")
  1580.  
  1581. (put 'paragraphindent 'texinfo-format 'texinfo-paragraphindent)
  1582.  
  1583. (defun texinfo-paragraphindent ()
  1584.   "Specify the number of spaces for @refill to indent a paragraph.
  1585. Default is to leave the number of spaces as is."
  1586.   (let ((arg  (texinfo-parse-arg-discard)))
  1587.     (if (string= "asis" arg)
  1588.         (setq texinfo-paragraph-indent "asis")
  1589.       (setq texinfo-paragraph-indent (string-to-int arg)))))
  1590.  
  1591. (put 'refill 'texinfo-format 'texinfo-format-refill)
  1592. (defun texinfo-format-refill ()
  1593.   "Refill paragraph. Also, indent first line as set by @paragraphindent.
  1594. Default is to leave paragraph indentation as is."
  1595.   (texinfo-discard-command)
  1596.   (forward-paragraph -1)     
  1597.   (if (looking-at "[ \t\n]*$") (forward-line 1))
  1598.   ;; Do not indent if an entry in a list, table, or deffn,
  1599.   ;; or if paragraph is preceded by @noindent.
  1600.   ;; Otherwise, indent
  1601.   (cond 
  1602.    ;; delete a @noindent line and do not indent paragraph
  1603.    ((save-excursion (forward-line -1)
  1604.                     (looking-at "^@noindent")) 
  1605.     (forward-line -1)
  1606.     (delete-region (point) (progn (forward-line 1) (point))))
  1607.    ;; do nothing if "asis"
  1608.    ((equal texinfo-paragraph-indent "asis"))
  1609.    ;; do no indenting in list, etc.
  1610.    ((> texinfo-stack-depth 0))   
  1611.    ;; otherwise delete existing whitespace and indent
  1612.    (t 
  1613.     (delete-region (point) (progn (skip-chars-forward " \t") (point)))
  1614.     (insert (make-string texinfo-paragraph-indent ? ))))
  1615.   (forward-paragraph 1) 
  1616.   (forward-line -1)
  1617.   (end-of-line)
  1618.   (fill-paragraph nil))
  1619.  
  1620. (put 'noindent 'texinfo-format 'texinfo-noindent)
  1621. (defun texinfo-noindent ()  
  1622.   (save-excursion 
  1623.     (forward-paragraph 1)
  1624.     (if (search-backward "@refill"
  1625.                             (save-excursion (forward-line -1) (point)) t)
  1626.         () ; leave @noindent command so @refill command knows not to indent
  1627.       ;; else
  1628.       (texinfo-discard-line))))
  1629.  
  1630.  
  1631. ;;; Index generation
  1632.  
  1633. (put 'vindex 'texinfo-format 'texinfo-format-vindex)
  1634. (defun texinfo-format-vindex ()
  1635.   (texinfo-index 'texinfo-vindex))
  1636.  
  1637. (put 'cindex 'texinfo-format 'texinfo-format-cindex)
  1638. (defun texinfo-format-cindex ()
  1639.   (texinfo-index 'texinfo-cindex))
  1640.  
  1641. (put 'findex 'texinfo-format 'texinfo-format-findex)
  1642. (defun texinfo-format-findex ()
  1643.   (texinfo-index 'texinfo-findex))
  1644.  
  1645. (put 'pindex 'texinfo-format 'texinfo-format-pindex)
  1646. (defun texinfo-format-pindex ()
  1647.   (texinfo-index 'texinfo-pindex))
  1648.  
  1649. (put 'tindex 'texinfo-format 'texinfo-format-tindex)
  1650. (defun texinfo-format-tindex ()
  1651.   (texinfo-index 'texinfo-tindex))
  1652.  
  1653. (put 'kindex 'texinfo-format 'texinfo-format-kindex)
  1654. (defun texinfo-format-kindex ()
  1655.   (texinfo-index 'texinfo-kindex))
  1656.  
  1657. (defun texinfo-index (indexvar)
  1658.   (let ((arg (texinfo-parse-expanded-arg)))
  1659.     (texinfo-discard-command)
  1660.     (set indexvar
  1661.      (cons (list arg
  1662.                      texinfo-last-node
  1663.                      ;; Region formatting may not provide last node position.
  1664.              (if texinfo-last-node-pos
  1665.                          (1+ (count-lines texinfo-last-node-pos (point)))
  1666.                        1))
  1667.            (symbol-value indexvar)))))
  1668.  
  1669. (defconst texinfo-indexvar-alist
  1670.   '(("cp" . texinfo-cindex)
  1671.     ("fn" . texinfo-findex)
  1672.     ("vr" . texinfo-vindex)
  1673.     ("tp" . texinfo-tindex)
  1674.     ("pg" . texinfo-pindex)
  1675.     ("ky" . texinfo-kindex)))
  1676.  
  1677.  
  1678. ;;; @defindex   @defcodeindex
  1679. (put 'defindex 'texinfo-format 'texinfo-format-defindex)
  1680. (put 'defcodeindex 'texinfo-format 'texinfo-format-defindex)
  1681.  
  1682. (defun texinfo-format-defindex ()
  1683.   (let* ((index-name (texinfo-parse-arg-discard)) ; eg: `aa'
  1684.          (indexing-command (intern (concat index-name "index")))
  1685.          (index-formatting-command      ; eg: `texinfo-format-aaindex'
  1686.           (intern (concat "texinfo-format-" index-name "index")))
  1687.          (index-alist-name              ; eg: `texinfo-aaindex'
  1688.           (intern (concat "texinfo-" index-name "index"))))
  1689.  
  1690.     (set index-alist-name nil)
  1691.  
  1692.     (put indexing-command               ; eg, aaindex
  1693.          'texinfo-format
  1694.          index-formatting-command)      ; eg, texinfo-format-aaindex
  1695.  
  1696.     ;; eg: "aa" . texinfo-aaindex
  1697.     (or (assoc index-name texinfo-indexvar-alist)
  1698.         (setq texinfo-indexvar-alist
  1699.               (cons
  1700.                (cons index-name
  1701.                      index-alist-name)
  1702.                texinfo-indexvar-alist)))
  1703.  
  1704.     (fset index-formatting-command
  1705.           (list 'lambda 'nil
  1706.                 (list 'texinfo-index 
  1707.                       (list 'quote index-alist-name))))))
  1708.  
  1709.  
  1710. ;;; @synindex   @syncodeindex
  1711.  
  1712. (put 'synindex 'texinfo-format 'texinfo-format-synindex)
  1713. (put 'syncodeindex 'texinfo-format 'texinfo-format-synindex)
  1714.  
  1715. (defun texinfo-format-synindex ()
  1716.   (let* ((args (texinfo-parse-arg-discard))
  1717.          (second (cdr (read-from-string args)))
  1718.          (joiner (symbol-name (car (read-from-string args))))
  1719.          (joined (symbol-name (car (read-from-string args second)))))
  1720.  
  1721.     (if (assoc joiner texinfo-short-index-cmds-alist)
  1722.         (put
  1723.           (cdr (assoc joiner texinfo-short-index-cmds-alist))
  1724.          'texinfo-format
  1725.          (or (cdr (assoc joined texinfo-short-index-format-cmds-alist))
  1726.              (intern (concat "texinfo-format-" joined "index"))))
  1727.       (put
  1728.        (intern (concat joiner "index"))
  1729.        'texinfo-format
  1730.        (or (cdr(assoc joined texinfo-short-index-format-cmds-alist))
  1731.            (intern (concat "texinfo-format-" joined "index")))))))
  1732.  
  1733. (defconst texinfo-short-index-cmds-alist
  1734.   '(("cp" . cindex)
  1735.     ("fn" . findex)
  1736.     ("vr" . vindex)
  1737.     ("tp" . tindex)
  1738.     ("pg" . pindex)
  1739.     ("ky" . kindex)))
  1740.  
  1741. (defconst texinfo-short-index-format-cmds-alist
  1742.   '(("cp" . texinfo-format-cindex)
  1743.     ("fn" . texinfo-format-findex)
  1744.     ("vr" . texinfo-format-vindex)
  1745.     ("tp" . texinfo-format-tindex)
  1746.     ("pg" . texinfo-format-pindex)
  1747.     ("ky" . texinfo-format-kindex)))
  1748.  
  1749.  
  1750. ;;; Sort and index (for VMS)
  1751.  
  1752. ;; Sort an index which is in the current buffer between START and END.
  1753. ;; Used on VMS, where the `sort' utility is not available.
  1754. (defun texinfo-sort-region (start end)
  1755.   (require 'sort)
  1756.   (save-restriction
  1757.     (narrow-to-region start end)
  1758.     (sort-subr nil 'forward-line 'end-of-line 'texinfo-sort-startkeyfun)))
  1759.  
  1760. ;; Subroutine for sorting an index.
  1761. ;; At start of a line, return a string to sort the line under.
  1762. (defun texinfo-sort-startkeyfun ()
  1763.   (let ((line
  1764.      (buffer-substring (point) (save-excursion (end-of-line) (point)))))
  1765.     ;; Canonicalize whitespace and eliminate funny chars.
  1766.     (while (string-match "[ \t][ \t]+\\|[^a-z0-9 ]+" line)
  1767.       (setq line (concat (substring line 0 (match-beginning 0))
  1768.              " "
  1769.              (substring line (match-end 0) (length line)))))
  1770.     line))
  1771.  
  1772.  
  1773. ;;; @printindex
  1774.  
  1775. (put 'printindex 'texinfo-format 'texinfo-format-printindex)
  1776.  
  1777. (defun texinfo-format-printindex ()
  1778.   (let ((indexelts (symbol-value
  1779.             (cdr (assoc (texinfo-parse-arg-discard)
  1780.                 texinfo-indexvar-alist))))
  1781.     opoint)
  1782.     (insert "\n* Menu:\n\n")
  1783.     (setq opoint (point))
  1784.     (texinfo-print-index nil indexelts)
  1785.  
  1786.     (if (eq system-type 'vax-vms)
  1787.         (texinfo-sort-region opoint (point))
  1788.       (shell-command-on-region opoint (point) "sort -fd" 1))))
  1789.  
  1790. (defun texinfo-print-index (file indexelts)
  1791.   (while indexelts
  1792.     (if (stringp (car (car indexelts)))
  1793.         (progn
  1794.           (insert "* " (car (car indexelts)) ": " )
  1795.           (indent-to 32)
  1796.           (insert
  1797.            (if file (concat "(" file ")") "")
  1798.            (nth 1 (car indexelts)) ".")
  1799.           (indent-to 54)
  1800.           (insert
  1801.            (if (nth 2 (car indexelts))
  1802.                (format "  %d." (nth 2 (car indexelts)))
  1803.              "")
  1804.            "\n"))
  1805.       ;; index entries from @include'd file
  1806.       (texinfo-print-index (nth 1 (car indexelts))
  1807.                (nth 2 (car indexelts))))
  1808.     (setq indexelts (cdr indexelts))))
  1809.  
  1810.  
  1811. ;;; Glyphs: @equiv, @error, etc
  1812.  
  1813. ;; @equiv           to show that two expressions are equivalent
  1814. ;; @error           to show an error message
  1815. ;; @expansion       to show what a macro expands to
  1816. ;; @point           to show the location of point in an example
  1817. ;; @print           to show what an evaluated expression prints
  1818. ;; @result          to indicate the value returned by an expression
  1819.  
  1820. (put 'equiv 'texinfo-format 'texinfo-format-equiv)
  1821. (defun texinfo-format-equiv ()
  1822.   (texinfo-parse-arg-discard)
  1823.   (insert "=="))
  1824.  
  1825. (put 'error 'texinfo-format 'texinfo-format-error)
  1826. (defun texinfo-format-error ()
  1827.   (texinfo-parse-arg-discard)
  1828.   (insert "error-->"))
  1829.  
  1830. (put 'expansion 'texinfo-format 'texinfo-format-expansion)
  1831. (defun texinfo-format-expansion ()
  1832.   (texinfo-parse-arg-discard)
  1833.   (insert "==>"))
  1834.  
  1835. (put 'point 'texinfo-format 'texinfo-format-point)
  1836. (defun texinfo-format-point ()
  1837.   (texinfo-parse-arg-discard)
  1838.   (insert "-!-"))
  1839.  
  1840. (put 'print 'texinfo-format 'texinfo-format-print)
  1841. (defun texinfo-format-print ()
  1842.   (texinfo-parse-arg-discard)
  1843.   (insert "-|"))
  1844.  
  1845. (put 'result 'texinfo-format 'texinfo-format-result)
  1846. (defun texinfo-format-result ()
  1847.   (texinfo-parse-arg-discard)
  1848.   (insert "=>"))
  1849.  
  1850.  
  1851. ;;; Definition formatting: @deffn, @defun, etc
  1852.  
  1853. ;; What definition formatting produces:
  1854. ;;
  1855. ;; @deffn category name args...
  1856. ;;     In Info, `Category: name ARGS'
  1857. ;;     In index: name:  node. line#.
  1858. ;;
  1859. ;; @defvr category name 
  1860. ;;     In Info, `Category: name'
  1861. ;;     In index: name:  node. line#.
  1862. ;;
  1863. ;; @deftp category name attributes...
  1864. ;; `category name attributes...'       Note: @deftp args in lower case.
  1865. ;;     In index: name:  node. line#.
  1866. ;;
  1867. ;; Specialized function-like or variable-like entity:
  1868. ;;
  1869. ;; @defun, @defmac, @defspec, @defvar, @defopt
  1870. ;;
  1871. ;; @defun name args           In Info, `Function: name ARGS'
  1872. ;; @defmac name args          In Info, `Macro: name ARGS'
  1873. ;; @defvar name               In Info, `Variable: name'
  1874. ;; etc.
  1875. ;;     In index: name:  node. line#.
  1876. ;;
  1877. ;; Generalized typed-function-like or typed-variable-like entity:
  1878. ;; @deftypefn category data-type name args...
  1879. ;;     In Info, `Category:  data-type name args...'
  1880. ;; @deftypevr category data-type name 
  1881. ;;     In Info, `Category:  data-type name'
  1882. ;;     In index: name:  node. line#.
  1883. ;;
  1884. ;; Specialized typed-function-like or typed-variable-like entity:
  1885. ;; @deftypefun data-type name args...
  1886. ;;     In Info, `Function:  data-type name ARGS'
  1887. ;;     In index: name:  node. line#.   
  1888. ;;
  1889. ;; @deftypevar data-type name 
  1890. ;;     In Info, `Variable:  data-type name'
  1891. ;;     In index: name:  node. line#.   but include args after name!?
  1892. ;;
  1893. ;; Generalized object oriented entity: 
  1894. ;; @defop category class name args...
  1895. ;;     In Info, `Category on class: name ARG'
  1896. ;;     In index: name on class: node. line#.
  1897. ;;
  1898. ;; @defcv category class name         
  1899. ;;     In Info, `Category of class: name'
  1900. ;;     In index: name of class: node. line#.
  1901. ;;
  1902. ;; Specialized object oriented entity:
  1903. ;; @defmethod class name args... 
  1904. ;;     In Info, `Method on class: name ARGS'
  1905. ;;     In index: name on class: node. line#.
  1906. ;;
  1907. ;; @defivar class name
  1908. ;;     In Info, `Instance variable of class: name'
  1909. ;;     In index: name of class: node. line#.
  1910.  
  1911.  
  1912. ;;; The definition formatting functions
  1913.  
  1914. (defun texinfo-format-defun ()
  1915.   (texinfo-push-stack 'defun nil)
  1916.   (setq fill-column (- fill-column 5))
  1917.   (texinfo-format-defun-1 t))
  1918.  
  1919. (defun texinfo-end-defun ()
  1920.   (setq fill-column (+ fill-column 5))
  1921.   (texinfo-discard-command)
  1922.   (let ((start (nth 1 (texinfo-pop-stack 'defun))))
  1923.     (texinfo-do-itemize start)
  1924.     ;; Delete extra newline inserted after header.
  1925.     (save-excursion
  1926.       (goto-char start)
  1927.       (delete-char -1))))
  1928.  
  1929. (defun texinfo-format-defunx ()
  1930.   (texinfo-format-defun-1 nil))
  1931.  
  1932. (defun texinfo-format-defun-1 (first-p)
  1933.   (let ((parse-args (texinfo-format-parse-defun-args))
  1934.     (command-type (get texinfo-command-name 'texinfo-defun-type)))
  1935.     (texinfo-discard-command)
  1936.     ;; Delete extra newline inserted after previous header line.
  1937.     (if (not first-p)
  1938.     (delete-char -1))
  1939.     (funcall
  1940.      (get texinfo-command-name 'texinfo-deffn-formatting-property) parse-args)
  1941.     ;; Insert extra newline so that paragraph filling does not mess
  1942.     ;; with header line.
  1943.     (insert "\n\n")
  1944.     (rplaca (cdr (cdr (car texinfo-stack))) (point))
  1945.     (funcall
  1946.      (get texinfo-command-name 'texinfo-defun-indexing-property) parse-args)))
  1947.  
  1948. ;;; Formatting the first line of a definition
  1949.  
  1950. ;; @deffn, @defvr, @deftp
  1951. (put 'deffn 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
  1952. (put 'deffnx 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
  1953. (put 'defvr 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
  1954. (put 'defvrx 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
  1955. (put 'deftp 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
  1956. (put 'deftpx 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
  1957. (defun texinfo-format-deffn (parsed-args)
  1958.   ;; Generalized function-like, variable-like, or generic data-type entity:
  1959.   ;; @deffn category name args...
  1960.   ;;     In Info, `Category: name ARGS'
  1961.   ;; @deftp category name attributes...
  1962.   ;; `category name attributes...'       Note: @deftp args in lower case.
  1963.   (let ((category (car parsed-args))
  1964.         (name (car (cdr parsed-args)))
  1965.         (args (cdr (cdr parsed-args))))
  1966.     (insert " -- " category ": " name)
  1967.     (while args
  1968.       (insert " "
  1969.               (if (or (= ?& (aref (car args) 0))
  1970.                       (eq (eval (car command-type)) 'deftp-type))
  1971.                   (car args)
  1972.                 (upcase (car args))))
  1973.       (setq args (cdr args)))))
  1974.  
  1975. ;; @defun, @defmac, @defspec, @defvar, @defopt: Specialized, simple
  1976. (put 'defun 'texinfo-deffn-formatting-property
  1977.      'texinfo-format-specialized-defun)
  1978. (put 'defunx 'texinfo-deffn-formatting-property
  1979.      'texinfo-format-specialized-defun)
  1980. (put 'defmac 'texinfo-deffn-formatting-property
  1981.      'texinfo-format-specialized-defun)
  1982. (put 'defmacx 'texinfo-deffn-formatting-property
  1983.      'texinfo-format-specialized-defun)
  1984. (put 'defspec 'texinfo-deffn-formatting-property
  1985.      'texinfo-format-specialized-defun)
  1986. (put 'defspecx 'texinfo-deffn-formatting-property
  1987.      'texinfo-format-specialized-defun)
  1988. (put 'defvar 'texinfo-deffn-formatting-property
  1989.      'texinfo-format-specialized-defun)
  1990. (put 'defvarx 'texinfo-deffn-formatting-property
  1991.      'texinfo-format-specialized-defun)
  1992. (put 'defopt 'texinfo-deffn-formatting-property
  1993.      'texinfo-format-specialized-defun)
  1994. (put 'defoptx 'texinfo-deffn-formatting-property
  1995.      'texinfo-format-specialized-defun)
  1996. (defun texinfo-format-specialized-defun (parsed-args)
  1997.   ;; Specialized function-like or variable-like entity:
  1998.   ;; @defun name args           In Info, `Function: Name ARGS'
  1999.   ;; @defmac name args          In Info, `Macro: Name ARGS'
  2000.   ;; @defvar name               In Info, `Variable: Name'
  2001.   ;; Use cdr of command-type to determine category:
  2002.   (let ((category (car (cdr command-type)))
  2003.         (name (car parsed-args))
  2004.         (args (cdr parsed-args)))
  2005.     (insert " -- " category ": " name)
  2006.     (while args
  2007.       (insert " "
  2008.               (if (= ?& (aref (car args) 0))
  2009.                   (car args)
  2010.                 (upcase (car args))))
  2011.       (setq args (cdr args)))))
  2012.  
  2013. ;; @deftypefn, @deftypevr: Generalized typed
  2014. (put 'deftypefn 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn)
  2015. (put 'deftypefnx 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn)
  2016. (put 'deftypevr 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn)
  2017. (put 'deftypevrx 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn)
  2018. (defun texinfo-format-deftypefn (parsed-args)
  2019.   ;; Generalized typed-function-like or typed-variable-like entity:
  2020.   ;; @deftypefn category data-type name args...
  2021.   ;;     In Info, `Category:  data-type name args...'
  2022.   ;; @deftypevr category data-type name 
  2023.   ;;     In Info, `Category:  data-type name'
  2024.   ;; Note: args in lower case, unless modified in command line.
  2025.   (let ((category (car parsed-args))
  2026.         (data-type (car (cdr parsed-args)))
  2027.         (name (car (cdr (cdr parsed-args))))
  2028.         (args (cdr (cdr (cdr parsed-args)))))
  2029.     (insert " -- " category ": " data-type " " name)
  2030.     (while args
  2031.       (insert " " (car args))
  2032.       (setq args (cdr args)))))
  2033.  
  2034. ;; @deftypefun, @deftypevar: Specialized typed
  2035. (put 'deftypefun 'texinfo-deffn-formatting-property 'texinfo-format-deftypefun)
  2036. (put 'deftypefunx 'texinfo-deffn-formatting-property
  2037.      'texinfo-format-deftypefun)
  2038. (put 'deftypevar 'texinfo-deffn-formatting-property 'texinfo-format-deftypefun)
  2039. (put 'deftypevarx 'texinfo-deffn-formatting-property
  2040.      'texinfo-format-deftypefun)
  2041. (defun texinfo-format-deftypefun (parsed-args)
  2042.   ;; Specialized typed-function-like or typed-variable-like entity:
  2043.   ;; @deftypefun data-type name args...
  2044.   ;;     In Info, `Function:  data-type name ARGS'
  2045.   ;; @deftypevar data-type name 
  2046.   ;;     In Info, `Variable:  data-type name'
  2047.   ;; Note: args in lower case, unless modified in command line.
  2048.   ;; Use cdr of command-type to determine category:
  2049.   (let ((category (car (cdr command-type)))
  2050.         (data-type (car parsed-args))
  2051.         (name (car (cdr  parsed-args)))
  2052.         (args (cdr (cdr parsed-args))))
  2053.     (insert " -- " category ": " data-type " " name)
  2054.     (while args
  2055.       (insert " " (car args))
  2056.       (setq args (cdr args)))))
  2057.  
  2058. ;; @defop: Generalized object-oriented
  2059. (put 'defop 'texinfo-deffn-formatting-property 'texinfo-format-defop)
  2060. (put 'defopx 'texinfo-deffn-formatting-property 'texinfo-format-defop)
  2061. (defun texinfo-format-defop (parsed-args)
  2062.   ;; Generalized object oriented entity: 
  2063.   ;; @defop category class name args...
  2064.   ;;     In Info, `Category on class: name ARG'
  2065.   ;; Note: args in upper case; use of `on'
  2066.   (let ((category (car parsed-args))
  2067.         (class (car (cdr parsed-args)))
  2068.         (name (car (cdr (cdr parsed-args))))
  2069.         (args (cdr (cdr (cdr parsed-args)))))
  2070.     (insert " -- " category " on " class ": " name)
  2071.     (while args
  2072.       (insert " " (upcase (car args)))
  2073.       (setq args (cdr args)))))
  2074.  
  2075. ;; @defcv: Generalized object-oriented
  2076. (put 'defcv 'texinfo-deffn-formatting-property 'texinfo-format-defcv)
  2077. (put 'defcvx 'texinfo-deffn-formatting-property 'texinfo-format-defcv)
  2078. (defun texinfo-format-defcv (parsed-args)
  2079.   ;; Generalized object oriented entity: 
  2080.   ;; @defcv category class name         
  2081.   ;;     In Info, `Category of class: name'
  2082.   ;; Note: args in upper case; use of `of'
  2083.   (let ((category (car parsed-args))
  2084.         (class (car (cdr parsed-args)))
  2085.         (name (car (cdr (cdr parsed-args))))
  2086.         (args (cdr (cdr (cdr parsed-args)))))
  2087.     (insert " -- " category " of " class ": " name)
  2088.     (while args
  2089.       (insert " " (upcase (car args)))
  2090.       (setq args (cdr args)))))
  2091.  
  2092. ;; @defmethod: Specialized object-oriented
  2093. (put 'defmethod 'texinfo-deffn-formatting-property 'texinfo-format-defmethod)
  2094. (put 'defmethodx 'texinfo-deffn-formatting-property 'texinfo-format-defmethod)
  2095. (defun texinfo-format-defmethod (parsed-args)
  2096.   ;; Specialized object oriented entity:
  2097.   ;; @defmethod class name args... 
  2098.   ;;     In Info, `Method on class: name ARGS'
  2099.   ;; Note: args in upper case; use of `on'
  2100.   ;; Use cdr of command-type to determine category:
  2101.   (let ((category (car (cdr command-type)))
  2102.         (class (car parsed-args))
  2103.         (name (car (cdr  parsed-args)))
  2104.         (args (cdr  (cdr parsed-args))))
  2105.     (insert " -- " category " on " class ": " name)
  2106.     (while args
  2107.       (insert " " (upcase (car args)))
  2108.       (setq args (cdr args)))))
  2109.  
  2110. ;; @defivar: Specialized object-oriented
  2111. (put 'defivar 'texinfo-deffn-formatting-property 'texinfo-format-defivar)
  2112. (put 'defivarx 'texinfo-deffn-formatting-property 'texinfo-format-defivar)
  2113. (defun texinfo-format-defivar (parsed-args)
  2114.   ;; Specialized object oriented entity:
  2115.   ;; @defivar class name
  2116.   ;;     In Info, `Instance variable of class: name'
  2117.   ;; Note: args in upper case; use of `of'
  2118.   ;; Use cdr of command-type to determine category:
  2119.   (let ((category (car (cdr command-type)))
  2120.         (class (car parsed-args))
  2121.         (name (car (cdr  parsed-args)))
  2122.         (args (cdr  (cdr parsed-args))))
  2123.     (insert " -- " category " of " class ": " name)
  2124.     (while args
  2125.       (insert " " (upcase (car args)))
  2126.       (setq args (cdr args)))))
  2127.  
  2128.  
  2129. ;;; Indexing for definitions
  2130.  
  2131. ;; An index entry has three parts: the `entry proper', the node name, and the
  2132. ;; line number.  Depending on the which command is used, the entry is
  2133. ;; formatted differently:
  2134. ;;
  2135. ;; @defun, 
  2136. ;; @defmac, 
  2137. ;; @defspec, 
  2138. ;; @defvar, 
  2139. ;; @defopt          all use their 1st argument as the entry-proper 
  2140. ;;
  2141. ;; @deffn, 
  2142. ;; @defvr, 
  2143. ;; @deftp 
  2144. ;; @deftypefun
  2145. ;; @deftypevar      all use their 2nd argument as the entry-proper
  2146. ;;
  2147. ;; @deftypefn, 
  2148. ;; @deftypevr       both use their 3rd argument as the entry-proper  
  2149. ;;
  2150. ;; @defmethod       uses its 2nd and 1st arguments as an entry-proper 
  2151. ;;                    formatted: NAME on CLASS
  2152.  
  2153. ;; @defop           uses its 3rd and 2nd arguments as an entry-proper 
  2154. ;;                    formatted: NAME on CLASS
  2155. ;;        
  2156. ;; @defivar         uses its 2nd and 1st arguments as an entry-proper
  2157. ;;                    formatted: NAME of CLASS
  2158. ;;
  2159. ;; @defcv           uses its 3rd and 2nd argument as an entry-proper
  2160. ;;                    formatted: NAME of CLASS
  2161.  
  2162. (put 'defun 'texinfo-defun-indexing-property 'texinfo-index-defun)
  2163. (put 'defunx 'texinfo-defun-indexing-property 'texinfo-index-defun)
  2164. (put 'defmac 'texinfo-defun-indexing-property 'texinfo-index-defun)
  2165. (put 'defmacx 'texinfo-defun-indexing-property 'texinfo-index-defun)
  2166. (put 'defspec 'texinfo-defun-indexing-property 'texinfo-index-defun)
  2167. (put 'defspecx 'texinfo-defun-indexing-property 'texinfo-index-defun)
  2168. (put 'defvar 'texinfo-defun-indexing-property 'texinfo-index-defun)
  2169. (put 'defvarx 'texinfo-defun-indexing-property 'texinfo-index-defun)
  2170. (put 'defopt  'texinfo-defun-indexing-property 'texinfo-index-defun)
  2171. (put 'defoptx  'texinfo-defun-indexing-property 'texinfo-index-defun)
  2172. (defun texinfo-index-defun (parsed-args)
  2173.   ;; use 1st parsed-arg  as entry-proper
  2174.   ;; `index-list' will be texinfo-findex or the like
  2175.   (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
  2176.     (set index-list
  2177.          (cons 
  2178.           ;; Three elements: entry-proper, node-name, line-number
  2179.           (list
  2180.            (car parsed-args)
  2181.            texinfo-last-node
  2182.            ;; Region formatting may not provide last node position.
  2183.            (if texinfo-last-node-pos
  2184.                (1+ (count-lines texinfo-last-node-pos (point)))
  2185.              1))
  2186.           (symbol-value index-list)))))
  2187.  
  2188. (put 'deffn 'texinfo-defun-indexing-property 'texinfo-index-deffn)
  2189. (put 'deffnx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
  2190. (put 'defvr 'texinfo-defun-indexing-property 'texinfo-index-deffn)
  2191. (put 'defvrx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
  2192. (put 'deftp 'texinfo-defun-indexing-property 'texinfo-index-deffn)
  2193. (put 'deftpx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
  2194. (put 'deftypefun 'texinfo-defun-indexing-property 'texinfo-index-deffn)
  2195. (put 'deftypefunx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
  2196. (put 'deftypevar 'texinfo-defun-indexing-property 'texinfo-index-deffn)
  2197. (put 'deftypevarx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
  2198. (defun texinfo-index-deffn (parsed-args) 
  2199.  ;; use 2nd parsed-arg  as entry-proper
  2200.   ;; `index-list' will be texinfo-findex or the like
  2201.   (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
  2202.     (set index-list
  2203.          (cons 
  2204.           ;; Three elements: entry-proper, node-name, line-number
  2205.           (list
  2206.            (car (cdr parsed-args))
  2207.            texinfo-last-node
  2208.            ;; Region formatting may not provide last node position.
  2209.            (if texinfo-last-node-pos
  2210.                (1+ (count-lines texinfo-last-node-pos (point)))
  2211.              1))
  2212.           (symbol-value index-list)))))
  2213.  
  2214. (put 'deftypefn 'texinfo-defun-indexing-property 'texinfo-index-deftypefn)
  2215. (put 'deftypefnx 'texinfo-defun-indexing-property 'texinfo-index-deftypefn)
  2216. (put 'deftypevr 'texinfo-defun-indexing-property 'texinfo-index-deftypefn)
  2217. (put 'deftypevrx 'texinfo-defun-indexing-property 'texinfo-index-deftypefn)
  2218. (defun texinfo-index-deftypefn (parsed-args)
  2219.   ;; use 3rd parsed-arg  as entry-proper
  2220.   ;; `index-list' will be texinfo-findex or the like
  2221.   (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
  2222.     (set index-list
  2223.          (cons 
  2224.           ;; Three elements: entry-proper, node-name, line-number
  2225.           (list
  2226.            (car (cdr (cdr parsed-args)))
  2227.            texinfo-last-node
  2228.            ;; Region formatting may not provide last node position.
  2229.            (if texinfo-last-node-pos
  2230.                (1+ (count-lines texinfo-last-node-pos (point)))
  2231.              1))
  2232.           (symbol-value index-list)))))
  2233.  
  2234. (put 'defmethod 'texinfo-defun-indexing-property 'texinfo-index-defmethod)
  2235. (put 'defmethodx 'texinfo-defun-indexing-property 'texinfo-index-defmethod)
  2236. (defun texinfo-index-defmethod (parsed-args)
  2237.   ;; use 2nd on 1st parsed-arg  as entry-proper
  2238.   ;; `index-list' will be texinfo-findex or the like
  2239.   (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
  2240.     (set index-list
  2241.          (cons 
  2242.           ;; Three elements: entry-proper, node-name, line-number
  2243.           (list
  2244.            (format "%s on %s"            
  2245.                    (car (cdr parsed-args))
  2246.                    (car parsed-args))
  2247.            texinfo-last-node
  2248.            ;; Region formatting may not provide last node position.
  2249.            (if texinfo-last-node-pos
  2250.                (1+ (count-lines texinfo-last-node-pos (point)))
  2251.              1))
  2252.           (symbol-value index-list)))))
  2253.  
  2254. (put 'defop 'texinfo-defun-indexing-property 'texinfo-index-defop)
  2255. (put 'defopx 'texinfo-defun-indexing-property 'texinfo-index-defop)
  2256. (defun texinfo-index-defop (parsed-args)
  2257.   ;; use 3rd on 2nd parsed-arg  as entry-proper
  2258.   ;; `index-list' will be texinfo-findex or the like
  2259.   (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
  2260.     (set index-list
  2261.          (cons 
  2262.           ;; Three elements: entry-proper, node-name, line-number
  2263.           (list
  2264.            (format "%s on %s"            
  2265.                    (car (cdr (cdr parsed-args)))
  2266.                    (car (cdr parsed-args)))
  2267.            texinfo-last-node
  2268.            ;; Region formatting may not provide last node position.
  2269.            (if texinfo-last-node-pos
  2270.                (1+ (count-lines texinfo-last-node-pos (point)))
  2271.              1))
  2272.           (symbol-value index-list)))))
  2273.  
  2274. (put 'defivar 'texinfo-defun-indexing-property 'texinfo-index-defivar)
  2275. (put 'defivarx 'texinfo-defun-indexing-property 'texinfo-index-defivar)
  2276. (defun texinfo-index-defivar (parsed-args)
  2277.   ;; use 2nd of 1st parsed-arg  as entry-proper
  2278.   ;; `index-list' will be texinfo-findex or the like
  2279.   (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
  2280.     (set index-list
  2281.          (cons 
  2282.           ;; Three elements: entry-proper, node-name, line-number
  2283.           (list
  2284.            (format "%s of %s"            
  2285.                    (car (cdr parsed-args))
  2286.                    (car parsed-args))
  2287.            texinfo-last-node
  2288.            ;; Region formatting may not provide last node position.
  2289.            (if texinfo-last-node-pos
  2290.                (1+ (count-lines texinfo-last-node-pos (point)))
  2291.              1))
  2292.           (symbol-value index-list)))))
  2293.  
  2294. (put 'defcv 'texinfo-defun-indexing-property 'texinfo-index-defcv)
  2295. (put 'defcvx 'texinfo-defun-indexing-property 'texinfo-index-defcv)
  2296. (defun texinfo-index-defcv (parsed-args)
  2297.   ;; use 3rd of 2nd parsed-arg  as entry-proper
  2298.   ;; `index-list' will be texinfo-findex or the like
  2299.   (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
  2300.     (set index-list
  2301.          (cons 
  2302.           ;; Three elements: entry-proper, node-name, line-number
  2303.           (list
  2304.            (format "%s of %s"            
  2305.                    (car (cdr (cdr parsed-args)))
  2306.                    (car (cdr parsed-args)))
  2307.            texinfo-last-node
  2308.            ;; Region formatting may not provide last node position.
  2309.            (if texinfo-last-node-pos
  2310.                (1+ (count-lines texinfo-last-node-pos (point)))
  2311.              1))
  2312.           (symbol-value index-list)))))
  2313.  
  2314.  
  2315. ;;; Properties for definitions
  2316.  
  2317. ;; Each definition command has six properties:
  2318. ;;
  2319. ;; 1. texinfo-deffn-formatting-property      to format definition line
  2320. ;; 2. texinfo-defun-indexing-property        to create index entry
  2321. ;; 3. texinfo-format                         formatting command
  2322. ;; 4. texinfo-end                            end formatting command
  2323. ;; 5. texinfo-defun-type                     type of deffn to format
  2324. ;; 6. texinfo-defun-index                    type of index to use
  2325. ;;
  2326. ;; The `x' forms of each definition command are used for the second
  2327. ;; and subsequent header lines.
  2328.  
  2329. ;; The texinfo-deffn-formatting-property and texinfo-defun-indexing-property
  2330. ;; are listed just before the appropriate formatting and indexing commands.
  2331.  
  2332. (put 'deffn 'texinfo-format 'texinfo-format-defun)
  2333. (put 'deffnx 'texinfo-format 'texinfo-format-defunx)
  2334. (put 'deffn 'texinfo-end 'texinfo-end-defun)
  2335. (put 'deffn 'texinfo-defun-type '('deffn-type nil))
  2336. (put 'deffnx 'texinfo-defun-type '('deffn-type nil))
  2337. (put 'deffn 'texinfo-defun-index 'texinfo-findex)
  2338. (put 'deffnx 'texinfo-defun-index 'texinfo-findex)
  2339.  
  2340. (put 'defun 'texinfo-format 'texinfo-format-defun)
  2341. (put 'defunx 'texinfo-format 'texinfo-format-defunx)
  2342. (put 'defun 'texinfo-end 'texinfo-end-defun)
  2343. (put 'defun 'texinfo-defun-type '('defun-type "Function"))
  2344. (put 'defunx 'texinfo-defun-type '('defun-type "Function"))
  2345. (put 'defun 'texinfo-defun-index 'texinfo-findex)
  2346. (put 'defunx 'texinfo-defun-index 'texinfo-findex)
  2347.  
  2348. (put 'defmac 'texinfo-format 'texinfo-format-defun)
  2349. (put 'defmacx 'texinfo-format 'texinfo-format-defunx)
  2350. (put 'defmac 'texinfo-end 'texinfo-end-defun)
  2351. (put 'defmac 'texinfo-defun-type '('defun-type "Macro"))
  2352. (put 'defmacx 'texinfo-defun-type '('defun-type "Macro"))
  2353. (put 'defmac 'texinfo-defun-index 'texinfo-findex)
  2354. (put 'defmacx 'texinfo-defun-index 'texinfo-findex)
  2355.  
  2356. (put 'defspec 'texinfo-format 'texinfo-format-defun)
  2357. (put 'defspecx 'texinfo-format 'texinfo-format-defunx)
  2358. (put 'defspec 'texinfo-end 'texinfo-end-defun)
  2359. (put 'defspec 'texinfo-defun-type '('defun-type "Special form"))
  2360. (put 'defspecx 'texinfo-defun-type '('defun-type "Special form"))
  2361. (put 'defspec 'texinfo-defun-index 'texinfo-findex)
  2362. (put 'defspecx 'texinfo-defun-index 'texinfo-findex)
  2363.  
  2364. (put 'defvr 'texinfo-format 'texinfo-format-defun)
  2365. (put 'defvrx 'texinfo-format 'texinfo-format-defunx)
  2366. (put 'defvr 'texinfo-end 'texinfo-end-defun)
  2367. (put 'defvr 'texinfo-defun-type '('deffn-type nil))
  2368. (put 'defvrx 'texinfo-defun-type '('deffn-type nil))
  2369. (put 'defvr 'texinfo-defun-index 'texinfo-vindex)
  2370. (put 'defvrx 'texinfo-defun-index 'texinfo-vindex)
  2371.  
  2372. (put 'defvar 'texinfo-format 'texinfo-format-defun)
  2373. (put 'defvarx 'texinfo-format 'texinfo-format-defunx)
  2374. (put 'defvar 'texinfo-end 'texinfo-end-defun)
  2375. (put 'defvar 'texinfo-defun-type '('defun-type "Variable"))
  2376. (put 'defvarx 'texinfo-defun-type '('defun-type "Variable"))
  2377. (put 'defvar 'texinfo-defun-index 'texinfo-vindex)
  2378. (put 'defvarx 'texinfo-defun-index 'texinfo-vindex)
  2379.  
  2380. (put 'defconst 'texinfo-format 'texinfo-format-defun)
  2381. (put 'defconstx 'texinfo-format 'texinfo-format-defunx)
  2382. (put 'defconst 'texinfo-end 'texinfo-end-defun)
  2383. (put 'defconst 'texinfo-defun-type '('defun-type "Constant"))
  2384. (put 'defconstx 'texinfo-defun-type '('defun-type "Constant"))
  2385. (put 'defconst 'texinfo-defun-index 'texinfo-vindex)
  2386. (put 'defconstx 'texinfo-defun-index 'texinfo-vindex)
  2387.  
  2388. (put 'defcmd 'texinfo-format 'texinfo-format-defun)
  2389. (put 'defcmdx 'texinfo-format 'texinfo-format-defunx)
  2390. (put 'defcmd 'texinfo-end 'texinfo-end-defun)
  2391. (put 'defcmd 'texinfo-defun-type '('defun-type "Command"))
  2392. (put 'defcmdx 'texinfo-defun-type '('defun-type "Command"))
  2393. (put 'defcmd 'texinfo-defun-index 'texinfo-findex)
  2394. (put 'defcmdx 'texinfo-defun-index 'texinfo-findex)
  2395.  
  2396. (put 'defopt 'texinfo-format 'texinfo-format-defun)
  2397. (put 'defoptx 'texinfo-format 'texinfo-format-defunx)
  2398. (put 'defopt 'texinfo-end 'texinfo-end-defun)
  2399. (put 'defopt 'texinfo-defun-type '('defun-type "User Option"))
  2400. (put 'defoptx 'texinfo-defun-type '('defun-type "User Option"))
  2401. (put 'defopt 'texinfo-defun-index 'texinfo-vindex)
  2402. (put 'defoptx 'texinfo-defun-index 'texinfo-vindex)
  2403.  
  2404. (put 'deftp 'texinfo-format 'texinfo-format-defun)
  2405. (put 'deftpx 'texinfo-format 'texinfo-format-defunx)
  2406. (put 'deftp 'texinfo-end 'texinfo-end-defun)
  2407. (put 'deftp 'texinfo-defun-type '('deftp-type nil))
  2408. (put 'deftpx 'texinfo-defun-type '('deftp-type nil))
  2409. (put 'deftp 'texinfo-defun-index 'texinfo-tindex)
  2410. (put 'deftpx 'texinfo-defun-index 'texinfo-tindex)
  2411.  
  2412. ;;; Object-oriented stuff is a little hairier.
  2413.  
  2414. (put 'defop 'texinfo-format 'texinfo-format-defun)
  2415. (put 'defopx 'texinfo-format 'texinfo-format-defunx)
  2416. (put 'defop 'texinfo-end 'texinfo-end-defun)
  2417. (put 'defop 'texinfo-defun-type '('defop-type nil))
  2418. (put 'defopx 'texinfo-defun-type '('defop-type nil))
  2419. (put 'defop 'texinfo-defun-index 'texinfo-findex)
  2420. (put 'defopx 'texinfo-defun-index 'texinfo-findex)
  2421.  
  2422. (put 'defmethod 'texinfo-format 'texinfo-format-defun)
  2423. (put 'defmethodx 'texinfo-format 'texinfo-format-defunx)
  2424. (put 'defmethod 'texinfo-end 'texinfo-end-defun)
  2425. (put 'defmethod 'texinfo-defun-type '('defmethod-type "Method"))
  2426. (put 'defmethodx 'texinfo-defun-type '('defmethod-type "Method"))
  2427. (put 'defmethod 'texinfo-defun-index 'texinfo-findex)
  2428. (put 'defmethodx 'texinfo-defun-index 'texinfo-findex)
  2429.  
  2430. (put 'defcv 'texinfo-format 'texinfo-format-defun)
  2431. (put 'defcvx 'texinfo-format 'texinfo-format-defunx)
  2432. (put 'defcv 'texinfo-end 'texinfo-end-defun)
  2433. (put 'defcv 'texinfo-defun-type '('defop-type nil))
  2434. (put 'defcvx 'texinfo-defun-type '('defop-type nil))
  2435. (put 'defcv 'texinfo-defun-index 'texinfo-vindex)
  2436. (put 'defcvx 'texinfo-defun-index 'texinfo-vindex)
  2437.  
  2438. (put 'defivar 'texinfo-format 'texinfo-format-defun)
  2439. (put 'defivarx 'texinfo-format 'texinfo-format-defunx)
  2440. (put 'defivar 'texinfo-end 'texinfo-end-defun)
  2441. (put 'defivar 'texinfo-defun-type '('defmethod-type "Instance variable"))
  2442. (put 'defivarx 'texinfo-defun-type '('defmethod-type "Instance variable"))
  2443. (put 'defivar 'texinfo-defun-index 'texinfo-vindex)
  2444. (put 'defivarx 'texinfo-defun-index 'texinfo-vindex)
  2445.  
  2446. ;;; Typed functions and variables
  2447.  
  2448. (put 'deftypefn 'texinfo-format 'texinfo-format-defun)
  2449. (put 'deftypefnx 'texinfo-format 'texinfo-format-defunx)
  2450. (put 'deftypefn 'texinfo-end 'texinfo-end-defun)
  2451. (put 'deftypefn 'texinfo-defun-type '('deftypefn-type nil))
  2452. (put 'deftypefnx 'texinfo-defun-type '('deftypefn-type nil))
  2453. (put 'deftypefn 'texinfo-defun-index 'texinfo-findex)
  2454. (put 'deftypefnx 'texinfo-defun-index 'texinfo-findex)
  2455.  
  2456. (put 'deftypefun 'texinfo-format 'texinfo-format-defun)
  2457. (put 'deftypefunx 'texinfo-format 'texinfo-format-defunx)
  2458. (put 'deftypefun 'texinfo-end 'texinfo-end-defun)
  2459. (put 'deftypefun 'texinfo-defun-type '('deftypefun-type "Function"))
  2460. (put 'deftypefunx 'texinfo-defun-type '('deftypefun-type "Function"))
  2461. (put 'deftypefun 'texinfo-defun-index 'texinfo-findex)
  2462. (put 'deftypefunx 'texinfo-defun-index 'texinfo-findex)
  2463.  
  2464. (put 'deftypevr 'texinfo-format 'texinfo-format-defun)
  2465. (put 'deftypevrx 'texinfo-format 'texinfo-format-defunx)
  2466. (put 'deftypevr 'texinfo-end 'texinfo-end-defun)
  2467. (put 'deftypevr 'texinfo-defun-type '('deftypefn-type nil))
  2468. (put 'deftypevrx 'texinfo-defun-type '('deftypefn-type nil))
  2469. (put 'deftypevr 'texinfo-defun-index 'texinfo-vindex)
  2470. (put 'deftypevrx 'texinfo-defun-index 'texinfo-vindex)
  2471.  
  2472. (put 'deftypevar 'texinfo-format 'texinfo-format-defun)
  2473. (put 'deftypevarx 'texinfo-format 'texinfo-format-defunx)
  2474. (put 'deftypevar 'texinfo-end 'texinfo-end-defun)
  2475. (put 'deftypevar 'texinfo-defun-type '('deftypevar-type "Variable"))
  2476. (put 'deftypevarx 'texinfo-defun-type '('deftypevar-type "Variable"))
  2477. (put 'deftypevar 'texinfo-defun-index 'texinfo-vindex)
  2478. (put 'deftypevarx 'texinfo-defun-index 'texinfo-vindex)
  2479.  
  2480.  
  2481. ;;; @set, @clear, @ifset, @ifclear
  2482.  
  2483. ;; If a flag is set with @set FLAG, then text between @ifset and @end
  2484. ;; ifset is formatted normally, but if the flag is is cleared with
  2485. ;; @clear FLAG, then the text is not formatted; it is ignored.
  2486.  
  2487. ;; If a flag is cleared with @clear FLAG, then text between @ifclear
  2488. ;; and @end ifclear is formatted normally, but if the flag is is set with
  2489. ;; @set FLAG, then the text is not formatted; it is ignored.  @ifclear
  2490. ;; is the opposite of @ifset.
  2491.  
  2492. ;; If a flag is set to a string with @set FLAG, 
  2493. ;; replace  @value{FLAG} with the string.
  2494. ;; If a flag with a value is cleared, 
  2495. ;; @value{FLAG} is invalid, 
  2496. ;; as if there had never been any @set FLAG previously.
  2497.  
  2498. (put 'clear 'texinfo-format 'texinfo-clear)
  2499. (defun texinfo-clear ()
  2500.   "Clear the value of the flag."
  2501.   (let* ((arg (texinfo-parse-arg-discard))
  2502.          (flag (car (read-from-string arg)))
  2503.          (value (substring arg (cdr (read-from-string arg)))))
  2504.     (put flag 'texinfo-whether-setp 'flag-cleared)
  2505.     (put flag 'texinfo-set-value "")))
  2506.  
  2507. (put 'set 'texinfo-format 'texinfo-set)
  2508. (defun texinfo-set ()
  2509.   "Set the value of the flag, optionally to a string.
  2510. The command  `@set foo This is a string.'
  2511. sets flag foo to the value: `This is a string.'
  2512. The command  `@value{foo}'  expands to the value."
  2513.   (let* ((arg (texinfo-parse-arg-discard))
  2514.          (flag (car (read-from-string arg)))
  2515.          (value (substring arg (cdr (read-from-string arg)))))
  2516.     (put flag 'texinfo-whether-setp 'flag-set)
  2517.     (put flag 'texinfo-set-value value)))
  2518.  
  2519. (put 'value 'texinfo-format 'texinfo-value)
  2520. (defun texinfo-value ()
  2521.   "Insert the string to which the flag is set.
  2522. The command  `@set foo This is a string.'
  2523. sets flag foo to the value: `This is a string.'
  2524. The command  `@value{foo}'  expands to the value."
  2525.   (let ((arg (texinfo-parse-arg-discard)))
  2526.     (cond ((and
  2527.             (eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
  2528.                 'flag-set)
  2529.             (get (car (read-from-string arg)) 'texinfo-set-value))
  2530.            (insert (get (car (read-from-string arg)) 'texinfo-set-value)))
  2531.           ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp) 
  2532.                'flag-cleared)
  2533.            (insert (format "{No value for \"%s\"}"  arg)))
  2534.           ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp) nil)
  2535.            (insert (format "{No value for \"%s\"}"  arg))))))
  2536.  
  2537. (put 'ifset 'texinfo-end 'texinfo-discard-command)
  2538. (put 'ifset 'texinfo-format 'texinfo-if-set)
  2539. (defun texinfo-if-set ()
  2540.   "If set, continue formatting; else do not format region up to @end ifset"
  2541.   (let ((arg (texinfo-parse-arg-discard)))
  2542.     (cond
  2543.      ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
  2544.           'flag-set)
  2545.       ;; Format the text (i.e., do not remove it); do nothing here.
  2546.       ())
  2547.      ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
  2548.           'flag-cleared)
  2549.       ;; Clear region (i.e., cause the text to be ignored).
  2550.       (delete-region texinfo-command-start
  2551.                        (progn (re-search-forward "@end ifset[ \t]*\n")
  2552.                               (point))))
  2553.      ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
  2554.           nil)
  2555.       (error  "@ifset flag `%s' is not defined by @set or @clear." arg)))))
  2556.  
  2557. (put 'ifclear 'texinfo-end 'texinfo-discard-command)
  2558. (put 'ifclear 'texinfo-format 'texinfo-if-clear)
  2559. (defun texinfo-if-clear ()
  2560.   "If clear, continue formatting; if set, do not format up to @end ifset"
  2561.   (let ((arg (texinfo-parse-arg-discard)))
  2562.     (cond
  2563.      ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
  2564.           'flag-set)
  2565.       ;; Clear region (i.e., cause the text to be ignored).
  2566.       (delete-region texinfo-command-start
  2567.                        (progn (re-search-forward "@end ifclear[ \t]*\n")
  2568.                               (point))))
  2569.      ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
  2570.           'flag-cleared)
  2571.       ;; Format the text (i.e., do not remove it); do nothing here.
  2572.       ())
  2573.      ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
  2574.           nil)
  2575.       (error  "@ifclear flag `%s' is not defined by @clear or @set." arg)))))
  2576.  
  2577.  
  2578. ;;; Process included files:  `@include' command
  2579.  
  2580. ;; Updated 19 October 1990
  2581. ;; In the original version, include files were ignored by Info but
  2582. ;; incorporated in to the printed manual.  To make references to the
  2583. ;; included file, the Texinfo source file has to refer to the included
  2584. ;; files using the `(filename)nodename' format for refering to other
  2585. ;; Info files.  Also, the included files had to be formatted on their
  2586. ;; own.  It was just like they were another file.
  2587.  
  2588. ;; Currently, include files are inserted into the buffer that is
  2589. ;; formatted for Info.  If large, the resulting info file is split and
  2590. ;; tagified.  For current include files to work, the master menu must
  2591. ;; refer to all the nodes, and the highest level nodes in the include
  2592. ;; files must have the correct next, prev, and up pointers.
  2593.  
  2594. ;; The included file may have an @setfilename and even an @settitle,
  2595. ;; but not an /input texinfo
  2596.  
  2597. ; Original definition:
  2598. ; (defun texinfo-format-include ()
  2599. ;   (let ((filename (texinfo-parse-arg-discard))
  2600. ;     (default-directory input-directory)
  2601. ;     subindex)
  2602. ;     (setq subindex
  2603. ;       (save-excursion
  2604. ;         (progn (find-file
  2605. ;             (cond ((file-readable-p (concat filename ".texinfo"))
  2606. ;                (concat filename ".texinfo"))
  2607. ;               ((file-readable-p (concat filename ".texi"))
  2608. ;                (concat filename ".texi"))
  2609. ;               ((file-readable-p (concat filename ".tex"))
  2610. ;                (concat filename ".tex"))
  2611. ;               ((file-readable-p filename)
  2612. ;                filename)
  2613. ;               (t (error "@include'd file %s not found"
  2614. ;                     filename))))
  2615. ;            (texinfo-format-buffer-1))))
  2616. ;     (texinfo-subindex 'texinfo-vindex (car subindex) (nth 1 subindex))
  2617. ;     (texinfo-subindex 'texinfo-findex (car subindex) (nth 2 subindex))
  2618. ;     (texinfo-subindex 'texinfo-cindex (car subindex) (nth 3 subindex))
  2619. ;     (texinfo-subindex 'texinfo-pindex (car subindex) (nth 4 subindex))
  2620. ;     (texinfo-subindex 'texinfo-tindex (car subindex) (nth 5 subindex))
  2621. ;     (texinfo-subindex 'texinfo-kindex (car subindex) (nth 6 subindex))))
  2622.  
  2623. (defun texinfo-subindex (indexvar file content)
  2624.   (set indexvar (cons (list 'recurse file content)
  2625.               (symbol-value indexvar))))
  2626.  
  2627. (put 'include 'texinfo-format 'texinfo-format-include)
  2628. (defun texinfo-format-include ()
  2629.   (let ((filename (concat input-directory
  2630.               (texinfo-parse-arg-discard)))
  2631.     (default-directory input-directory))
  2632.     (message "Reading: %s" filename)
  2633.     (save-excursion
  2634.       (save-restriction
  2635.         (narrow-to-region
  2636.          (point)
  2637.          (+ (point) (car (cdr (insert-file-contents filename)))))
  2638.         (goto-char (point-min))
  2639.         (texinfo-append-refill)
  2640.         (texinfo-format-convert (point-min) (point-max))))
  2641.     (setq last-input-buffer input-buffer)  ; to bypass setfilename
  2642.     ))
  2643.  
  2644.  
  2645. ;;; Numerous commands do nothing in Texinfo
  2646.  
  2647. ;; These commands are defined in texinfo.tex for printed output.
  2648.  
  2649. (put 'bye 'texinfo-format 'texinfo-discard-line)
  2650. (put 'c 'texinfo-format 'texinfo-discard-line-with-args)
  2651. (put 'comment 'texinfo-format 'texinfo-discard-line-with-args)
  2652. (put 'contents 'texinfo-format 'texinfo-discard-line-with-args)
  2653. (put 'finalout 'texinfo-format 'texinfo-discard-line)
  2654. (put 'group 'texinfo-end 'texinfo-discard-line-with-args)
  2655. (put 'group 'texinfo-format 'texinfo-discard-line-with-args)
  2656. (put 'headings 'texinfo-format 'texinfo-discard-line-with-args)
  2657. (put 'hsize 'texinfo-format 'texinfo-discard-line-with-args)
  2658. (put 'itemindent 'texinfo-format 'texinfo-discard-line-with-args)
  2659. (put 'lispnarrowing 'texinfo-format 'texinfo-discard-line-with-args)
  2660. (put 'need 'texinfo-format 'texinfo-discard-line-with-args)
  2661. (put 'nopara 'texinfo-format 'texinfo-discard-line-with-args)
  2662. (put 'page 'texinfo-format 'texinfo-discard-line-with-args)
  2663. (put 'parindent 'texinfo-format 'texinfo-discard-line-with-args)
  2664. (put 'setchapternewpage 'texinfo-format 'texinfo-discard-line-with-args)
  2665. (put 'setq 'texinfo-format 'texinfo-discard-line-with-args)
  2666. (put 'settitle 'texinfo-format 'texinfo-discard-line-with-args)
  2667. (put 'setx 'texinfo-format 'texinfo-discard-line-with-args)
  2668. (put 'shortcontents 'texinfo-format 'texinfo-discard-line-with-args)
  2669. (put 'smallbook 'texinfo-format 'texinfo-discard-line)
  2670. (put 'summarycontents 'texinfo-format 'texinfo-discard-line-with-args)
  2671.  
  2672.  
  2673. ;;; Some commands cannot be handled
  2674.  
  2675. (defun texinfo-unsupported ()
  2676.   (error "%s is not handled by texinfo"
  2677.      (buffer-substring texinfo-command-start texinfo-command-end)))
  2678.  
  2679. ;;; Batch formatting
  2680.  
  2681. (defun batch-texinfo-format ()
  2682.   "Runs  texinfo-format-buffer  on the files remaining on the command line.
  2683. Must be used only with -batch, and kills emacs on completion.
  2684. Each file will be processed even if an error occurred previously.
  2685. For example, invoke
  2686.   \"emacs -batch -funcall batch-texinfo-format $docs/ ~/*.texinfo\"."
  2687.   (if (not noninteractive)
  2688.       (error "batch-texinfo-format may only be used -batch."))
  2689.   (let ((version-control t)
  2690.     (auto-save-default nil)
  2691.     (find-file-run-dired nil)
  2692.     (kept-old-versions 259259)
  2693.     (kept-new-versions 259259))
  2694.     (let ((error 0)
  2695.       file
  2696.       (files ()))
  2697.       (while command-line-args-left
  2698.     (setq file (expand-file-name (car command-line-args-left)))
  2699.     (cond ((not (file-exists-p file))
  2700.            (message ">> %s does not exist!" file)
  2701.            (setq error 1
  2702.              command-line-args-left (cdr command-line-args-left)))
  2703.           ((file-directory-p file)
  2704.            (setq command-line-args-left
  2705.              (nconc (directory-files file)
  2706.                 (cdr command-line-args-left))))
  2707.           (t
  2708.            (setq files (cons file files)
  2709.              command-line-args-left (cdr command-line-args-left)))))
  2710.       (while files
  2711.     (setq file (car files)
  2712.           files (cdr files))
  2713.     (condition-case err
  2714.         (progn
  2715.           (if buffer-file-name (kill-buffer (current-buffer)))
  2716.           (find-file file)
  2717.           (buffer-flush-undo (current-buffer))
  2718.           (set-buffer-modified-p nil)
  2719.           (texinfo-mode)
  2720.           (message "texinfo formatting %s..." file)
  2721.           (texinfo-format-buffer nil)
  2722.           (if (buffer-modified-p)
  2723.           (progn (message "Saving modified %s" (buffer-file-name))
  2724.              (save-buffer))))
  2725.       (error
  2726.        (message ">> Error: %s" (prin1-to-string err))
  2727.        (message ">>  point at")
  2728.        (let ((s (buffer-substring (point)
  2729.                       (min (+ (point) 100)
  2730.                        (point-max))))
  2731.          (tem 0))
  2732.          (while (setq tem (string-match "\n+" s tem))
  2733.            (setq s (concat (substring s 0 (match-beginning 0))
  2734.                    "\n>>  "
  2735.                    (substring s (match-end 0)))
  2736.              tem (1+ tem)))
  2737.          (message ">>  %s" s))
  2738.        (setq error 1))))
  2739.       (kill-emacs error))))
  2740.  
  2741.  
  2742. ;;; Place `provide' at end of file.
  2743. (provide 'texinfmt)
  2744. ;;;;;;;;;;;;;;;; end texinfmt.el ;;;;;;;;;;;;;;;;
  2745.